2013-02-05 33 views
4

我考慮的Clojure /咒術作爲替代至R ,只是想知道如果Clojure的/咒術有能力做到以下幾點:SQL語句的的Clojure /咒術數據轉換功能

  1. 導入結果作爲一個數據集(我使用dbGetQuery在R中執行此操作)。
  2. 重塑數據集 - 將行轉換爲也稱爲「pivot」/「unpivot」的列 - 我在R中使用reshape,reshape2包(在R世界中稱爲熔化和鑄造數據)執行此操作。
  3. 保存重構數據設置爲

回答

2

您可能感興趣的core.matrix SQL表(我使用dbWriteTable功能做到這一點的R中RMySQL) - 這是一個項目,帶來多維數組和數值計算Clojure的功能。仍處於非常活躍的發展階段但已經可以使

特點:

  • 在乾淨的,功能性API
  • 正確多維數組
  • 使用Clojure數據,例如工作的慣用風格嵌套矢量[[1 2] [3 4]]可以自動用作2x2矩陣。
  • 您可能期望的所有陣列整形功能。
  • 所有常用的矩陣運算(乘法,縮放,行列式等)
  • 支持多個後端矩陣實現,例如, JBLAS高性能(使用本地代碼)

見一些示例代碼在這裏:

;; 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已獲得豐富的希基作爲一個正式的Clojure的contrib庫,並且很可能是咒術將來會切換到使用core.matrix。

SQL表的支持並不直接包含在core.matrix中,但它只是一個將clojure.java.jdbc的結果集轉換爲core.matrix數組的單線程支持。像下面這樣的應該做的伎倆:

(coerce [] (map vals resultset)) 

然後,你可以轉換和處理它與core.matrix不管你喜歡。

+0

令人興奮的看到在這方面取得的進展。我希望core.matrix能夠在包括Incanter在內的數字Clojure空間中實現一些復興活動。 – Peter