Yet Another Blog in Statistical Computing

I can calculate the motion of heavenly bodies but not the madness of people. -Isaac Newton

Read CSV Data File with Clojure

;; LOAD PACKAGES
user=> (use '(incanter core io))
nil

;; READ CSV FILE
user=> (def ds1 (read-dataset "../data/credit_count.csv" :header true :delim \,))
#'user/ds1

;; EXAMINE THE DATA
user=> ($ (range 0 3) :all ds1)
[:CARDHLDR :DEFAULT :AGE :ACADMOS :ADEPCNT :MAJORDRG :MINORDRG :OWNRENT :INCOME :SELFEMPL :INCPER :EXP_INC :SPENDING :LOGSPEND ]
[0 0 27.25 4 0 0 0 0 1200 0 18000 6.667E-4 " " "  "]
[0 0 40.8333321 111 3 0 0 1 4000 0 13500 2.222E-4 " " "  "]
[1 0 37.6666679 54 3 0 0 1 3666.6666667 0 11300 0.0332699 121.9896773 4.8039364]

;; CALCULATE SUMMARY BY GROUP
user=> ($rollup :mean :INCOME [:CARDHLDR :DEFAULT] ds1)
[:DEFAULT :CARDHLDR :INCOME]
[1 1 2156.117553547691]
[0 1 2653.2908642884945]
[0 0 2165.1530843234673]
Advertisements

Written by statcompute

March 14, 2015 at 3:23 pm

Posted in clojure, incanter

Tagged with ,

%d bloggers like this: