我认为Clojure / Incanter是R的替代品 并且只是想知道clojure / incanter是否有能力执行以下操作:
答案 0 :(得分:2)
您可能对core.matrix感兴趣 - 这是一个将多维数组和数值计算功能引入Clojure的项目。仍处于非常活跃的发展阶段,但已经可以使用。
特点:
[[1 2] [3 4]]
可以自动用作2x2矩阵。请参阅此处的示例代码:
;; a matrix can be defined using a nested vector
(def a (matrix [[2 0] [0 2]]))
;; core.matrix.operators overloads operators to work on matrices
(* a a)
;; a wide range of mathematical functions are defined for matrices
(sqrt a)
;; you can get rows and columns of matrices individually
(get-row a 0)
;; Java double arrays can be used as vectors
(* a (double-array [1 2]))
;; you can modify double arrays in place - they are examples of mutable vectors
(let [a (double-array [1 4 9])]
(sqrt! a) ;; "!" signifies an in-place operator
(seq a))
;; you can coerce matrices between different formats
(coerce [] (double-array [1 2 3]))
;; scalars can be used in many places that you can use a matrix
(* [1 2 3] 2)
;; operations on scalars alone behave as you would expect
(* 1 2 3 4 5)
;; you can do various functional programming tricks with matrices too
(emap inc [[1 2] [3 4]])
core.matrix已被Rich Hickey批准为官方Clojure contrib库,并且Incanter很可能会在未来切换到使用core.matrix。
SQL表支持不直接包含在core.matrix中,但它只是将结果集从clojure.java.jdbc转换为core.matrix数组的单行程序。像下面这样的东西可以做到这一点:
(coerce [] (map vals resultset))
然后你可以随心所欲地使用core.matrix转换和处理它。