Database Reference
In-Depth Information
:dependencies [[org.clojure/clojure "1.6.0"]
[incanter "1.5.5"]
[local.repo/JLink "9.0"]
[local.repo/clojuratica "2.0"]]
:source-paths ["src" "Clojuratica/src/clj"]
:resource-paths ["src/main/resource"
"/Applications/Mathematica.app/SystemFiles/Links/JLink"])
Moreover, you'll require those namespaces in your script or REPL:
(use 'clojuratica)
(require '[incanter.core :as i]
'incanter.io)
Finally, we'll use the dataset of racial census data that we compiled for the Grouping data with
$group-by recipe in Chapter 6 , Working with Incanter DataSets . We'll bind the ilename to the
name data-file . You can download this from http://www.ericrochester.com/clj-
data-analysis/data/all_160.P3.csv .
(def data-file "data/all_160.P3.csv")
How to do it…
In this recipe, we'll load some data into Clojure, deine a couple of wrapper functions that
call functions deined in Mathematica, and then we'll apply those functions to our Incanter
dataset, as shown here:
1.
First, we'll load the data:
(def data (incanter.io/read-dataset data-file :header true))
2. Next, we'll deine some wrapper functions to call Mathematica's Mean and Median
functions:
(defn mma-mean [dataset col]
(math (Mean ~(i/sel dataset :cols col))))
(defn mma-median [dataset col]
(math (Median ~(i/sel dataset :cols col))))
3.
Now we can call these functions just as we would call any other Clojure function:
user=> (mma-mean data :POP100)
230766493/29439
user=> (mma-median data :POP100)
1081
 
Search WWH ::




Custom Search