Yet Another Blog in Statistical Computing

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

Two Ways to Select Rows in Incanter

user=> (use '(incanter core io))
nil

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

user=> (sel iris :rows (range 3))
[: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"]

;; METHOD 1 - USING $WHERE 
user=> ($where {:Species {:in #{"virginica" "setosa"}} :Sepal.Length {:gt 5.5, :lt 6.0}} iris)
[:Sepal.Length :Sepal.Width :Petal.Length :Petal.Width :Species]
[5.8 4.0 1.2 0.2 "setosa"]
[5.7 4.4 1.5 0.4 "setosa"]
[5.7 3.8 1.7 0.3 "setosa"]
[5.8 2.7 5.1 1.9 "virginica"]
[5.7 2.5 5.0 2.0 "virginica"]
[5.8 2.8 5.1 2.4 "virginica"]
[5.6 2.8 4.9 2.0 "virginica"]
[5.8 2.7 5.1 1.9 "virginica"]
[5.9 3.0 5.1 1.8 "virginica"]

;; METHOD 2 - USING QUERY-DATASET
user=> (query-dataset iris {:Species {:in #{"virginica" "setosa"}} :Sepal.Length {:gt 5.5, :lt 6.0}})
[:Sepal.Length :Sepal.Width :Petal.Length :Petal.Width :Species]
[5.8 4.0 1.2 0.2 "setosa"]
[5.7 4.4 1.5 0.4 "setosa"]
[5.7 3.8 1.7 0.3 "setosa"]
[5.8 2.7 5.1 1.9 "virginica"]
[5.7 2.5 5.0 2.0 "virginica"]
[5.8 2.8 5.1 2.4 "virginica"]
[5.6 2.8 4.9 2.0 "virginica"]
[5.8 2.7 5.1 1.9 "virginica"]
[5.9 3.0 5.1 1.8 "virginica"]
Advertisements

Written by statcompute

March 15, 2015 at 1:35 am

Posted in clojure, incanter

Tagged with ,

%d bloggers like this: