Database Reference
In-Depth Information
How to do it…
For this recipe, we'll take some census data and add a column to show the change in
population between the 2000 and 2010 censuses:
1.
To begin, we'll need to read in the data:
(def data
(incanter.io/read-dataset data-file
:header true))
2.
If we look at the values in the ield for the 2000 census population, some of them
are empty. This will cause errors, so we'll replace those with zeros. Here's the function
to do that:
(defn check-int [x] (if (integer? x) x 0)) x 0))
3.
Now we can get the difference in population between the two censuses:
(def growth-rates
(->> data
(i/$map check-int :POP100.2000)
(i/minus (i/sel data :cols :POP100))
(i/dataset [:POP.DELTA])
(i/conj-cols data)))
4.
As we might expect, some places have grown and some have shrunk:
user=> (i/sel growth-rates
:cols [:NAME :POP100 :POP100.2000 :POP.DELTA]
:rows (range 5))
| :NAME | :POP100 | :POP100.2000 | :POP.DELTA |
|-----------------+---------+--------------+------------|
| Abingdon town | 8191 | 7780 | 411.0 |
| Accomac town | 519 | 547 | -28.0 |
| Alberta town | 298 | 306 | -8.0 |
| Alexandria city | 139966 | 128283 | 11683.0 |
| Allisonia CDP | 117 | | 117.0 |
 
Search WWH ::




Custom Search