Converting datasets to matrices
Although datasets are often convenient, many times we'll want to treat our data as a matrix from linear algebra. In Incanter, matrices store a table of doubles. This provides good performance in a compact data structure. Moreover, we'll need matrices many times because some of Incanter's functions, such as trans
, only operate on a matrix. Plus, it implements Clojure's ISeq interface, so interacting with matrices is also convenient.
Getting ready
For this recipe, we'll need the Incanter libraries, so we'll use this project.clj
file:
(defproject inc-dsets "0.1.0" :dependencies [[org.clojure/clojure "1.6.0"] [incanter "1.5.5"]])
We'll use the core
and io
namespaces, so we'll load these into our script or REPL:
(use '(incanter core io))
We'll use the Virginia census data that we've used periodically throughout the book. See the Managing program complexity with STM recipe from Chapter 3, Managing Complexity with Concurrent Programming, for information...