While we can filter datasets before we import them into Incanter, Incanter makes it easy to filter and create new datasets from existing ones. We'll take a look at its query language in this recipe.
We'll use the same dependencies, imports, and data that we did in the Using infix formulas in Incanter recipe.
Once we have the data, we query it using the $where
function.
For example, the following creates a dataset with the row for Richmond:
user=> (def richmond ($where {:NAME "Richmond city"} va-data)) #'user/richmond user=> richmond [:GEOID :SUMLEV :STATE :COUNTY :CBSA :CSA :NECTA :CNECTA :NAME :POP100 :HU100 :POP100.2000 :HU100.2000 :P035001 :P035001.2000] [5167000 160 51 "" "" "" "" "" "Richmond city" 204214 98349 197790 92282 41304 43649]
The queries can be more complicated, too. The following one picks out the small towns, ones with population less than 1,000:
user=> (def small ($where {:POP100 {:lte 1000}} va-data)) #'user...