Database Reference
In-Depth Information
Filtering datasets with $where
While we can ilter datasets before we import them into Incanter, Incanter makes it easy to
ilter and create new datasets from the existing ones. We'll take a look at its query language
in this recipe.
Getting ready
We'll use the same dependencies, imports, and data as we did in the Selecting columns
with $ recipe.
How to do it…
Once we have the data, we query it using the $where function:
1.
For example, this creates a dataset with a row for the percentage of China's total land
area that is used for agriculture:
user=> (def land-use
(i/$where {:Indicator-Code "AG.LND.AGRI.ZS"}
chn-data))
user=> (i/nrow land-use)
1
user=> (i/$ [:Indicator-Code :2000] land-use)
("AG.LND.AGRI.ZS" "56.2891584865366")
2.
The queries can be more complicated too. This expression picks out the data that
exists for 1962 by iltering any empty strings in that column:
user=> (i/$ (range 5) [:Indicator-Code :1962]
(i/$where {:1962 {:ne ""}} chn-data) )
| :Indicator-Code | :1962 |
|-------------------+-------------------|
| AG.AGR.TRAC.NO | 55360 |
| AG.LND.AGRI.K2 | 3460010 |
| AG.LND.AGRI.ZS | 37.0949187612906 |
| AG.LND.ARBL.HA | 103100000 |
| AG.LND.ARBL.HA.PC | 0.154858284392508 |
Incanter's query language is even more powerful than this, but these examples should show
you the basic structure and give you an idea of the possibilities.
 
Search WWH ::




Custom Search