Database Reference
In-Depth Information
4.
This is much more useful. We can also create a dataset by passing the column vector
and the row matrix separately to
dataset
:
user=> (def matrix-set-2
(dataset [:a :b :c]
[[1 2 3] [4 5 6]]))
#'user/matrix-set-2
user=> (nrow matrix-set-2)
2
user=> (col-names matrix-set-2)
[:c :b :a]
How it works…
The
to-dataset
function looks at the input and tries to process it intelligently. If given a
sequence of maps, the column names are taken from the keys of the irst map in the sequence.
Ultimately, it uses the
dataset
constructor to create the dataset. When you want the most
control, you should also use the dataset. It requires the dataset to be passed in as a column
vector and a row matrix. When the data is in this format or when we need the most control—to
rename the columns, for instance—we can use
dataset
.
See also…
Several recipes in
Chapter 1
,
Importing Data for Analysis
, look at how to load data from
different external sources into Incanter datasets.
Viewing datasets interactively with view
Being able to interact with our data programmatically is important, but sometimes it's also
helpful to be able to look at it. This can be especially useful when you do data exploration.
Getting ready
We'll need to have Incanter in our
project.clj
ile and script or REPL, so we'll use
the same setup as we did for the
Loading Incanter's sample datasets
recipe, as follows.
We'll also use the Iris dataset from that recipe.
(use '(incanter core datasets))