Database Reference
In-Depth Information
How it works…
To better understand how to use $where , let's break apart the last example:
($i/where {:1962 {:ne ""} } chn-data)
The query is expressed as a hashmap from ields to values (highlighted). As we saw in the
irst example, the value can be a raw value, either a literal or an expression. This tests for
inequality.
($i/where {:1962 {:ne ""}} chn-data)
Each test pair is associated with a ield in another hashmap (highlighted).
In this example, both the hashmaps shown only contain one key-value pair. However, they
might contain multiple pairs, which will all be ANDed together.
Incanter supports a number of test operators. The basic boolean tests are :$gt (greater
than), :$lt (less than), :$gte (greater than or equal to), :$lte (less than or equal to),
:$eq (equal to), and :$ne (not equal). There are also some operators that take sets as
parameters: :$in and :$nin (not in).
The last operator— :$fn —is interesting. It allows you to use any predicate function. For
example, this will randomly select approximately half of the dataset:
(def random-half
(i/$where {:Indicator-Code {:$fn (fn [_] (< (rand) 0.5))}}
chnchn-data))
There's more…
For full details of the query language, see the documentation for incanter.core/query-
dataset ( http://liebke.github.com/incanter/core-api.html#incanter.
core/query-dataset ) .
Grouping data with $group-by
Datasets often come with an inherent structure. Two or more rows might have the same
value in one column, and we might want to leverage that by grouping those rows together
in our analysis.
 
Search WWH ::




Custom Search