Search code examples
clojureincanter

What is the idiomatic way to obtain a sequence of columns from an incanter dataset?


What's the best way to get a sequence of columns (as vectors or whatever) from an Incanter data set?

I thought of:

(to-vect (trans (to-matrix my-dataset)))

But Ideally, I'd like a lazy sequence. Is there a better way?


Solution

  • Use the $ macro.

    => (def data (to-dataset [{:a 1 :b 2} {:a 3 :b 4}]))
    => ($ :a data)  ;; :a column
    => ($ 0 :all data) ;; first row
    
    => (type ($ :a data))
    clojure.lang.LazySeq