Frage

When selecting two columns from a dataset, the result has the two given column titles as expected. But when only specifying one column, the one resulting column loses it's title, instead, it is titled "0":

This makes it hard to use $order or whatever in later steps that take column names.

That is, this will work

(with-data data   
  (->> ($ [:foo :bar])
       ($order [:foo] :asc)
       (view)))

and this will fail

(with-data data
  (->> ($ [:foo])
       ($order [:foo] :asc)
       (view)))

Any ideas what is going wrong or what to do?

War es hilfreich?

Lösung

which version of Incanter are you using? This behavior was changed in recent versions, and at least 1.5.4 works correctly. But take into account that behavior of $ is different when you pass the column name as single element, and as vector:

incanter.main=> (def data (dataset [:foo :bar] [[:a :b] [:c :d]]))
#'incanter.main/data
incanter.main=> ($ :foo data)
(:a :c)
incanter.main=> ($ [:foo] data)

| :foo |
|------|
|   :a |
|   :c |

Andere Tipps

It sounds like you hit on the correct answer when you point out that in the single key case incanter simply returns a sequence. One way to get around this, though it could be a little less elegant is to simply request a second column and ignore the second result or put it into a sequence of maps after. Something only a little hackish like:

(map hash-map (repeat :key) result-seq)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top