Database Reference
In-Depth Information
$rollup
deines some standard aggregation functions (
:count
,
:sum
,
:min
,
:max
,
and
:mean
) but we can also use any other function that takes a collection of values and
returns a single value. This is what we did with
incanter.stats/sd
. For full details of the
$rollup
function and the aggregate keyword functions it provides, see the documentation at
As an aside, the numbers in the irst example, which calculated the mean, are expressed
as rational numbers. These are real numbers that are more precise than IEEE loating-point
numbers, which is what Clojure uses for its doubles. When Clojure divides two integers, we get
rational numbers. If you want to see loating-point numbers, you convert them by passing the
values to
float
:
user=> (/ 695433 172)
695433/172
user=> (float 695433/172)
4043.215
Working with changes in values
Sometimes, we are more interested in how values change over time, or across some other
progression, than we are in the values themselves. This information is latent in the data,
but making it explicit makes it easier to work with and visualize.
Getting ready
First, we'll use these dependencies in our
project.clj
:
(defproject statim "0.1.0"
:dependencies [[org.clojure/clojure "1.6.0"]
[incanter "1.5.5"]])
We also need to require Incanter in our script or REPL:
(require '[incanter.core :as i]
'incanter.io)
Finally, we'll use the Virginia census data. You can download the ile from
http://www.
(def data-file "data/all_160_in_51.P3.csv")