Yet Another Blog in Statistical Computing

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

Read Space-Delimited File with Clojure

;; load clojure libraries
user=> (use 'incanter.core 'incanter.io)
nil

;; import data file
user=> (def iris (read-dataset "../data/iris.dat" :header true :delim \space))
#'user/iris

;; show data header
user=> (col-names iris)
[:Sepal.Length :Sepal.Width :Petal.Length :Petal.Width :Species]

;; show first 3 data records with $
user=> ($ (range 0 3) :all iris)
[:Sepal.Length :Sepal.Width :Petal.Length :Petal.Width :Species]
[5.1 3.5 1.4 0.2 "setosa"]
[4.9 3.0 1.4 0.2 "setosa"]
[4.7 3.2 1.3 0.2 "setosa"]
Advertisements

Written by statcompute

March 9, 2015 at 2:13 am

Posted in clojure, incanter

Tagged with ,

%d bloggers like this: