Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I modify a column in an Incanter dataset?

I'd like to be able to transform an individual column in an incanter data set, and save the resulting data set to a new (csv) file. What is the simplest way to do that?

Essentially, I'd like to be able to map a function over a column in the data set, and replace the original column with this result.

like image 759
Rob Lachlan Avatar asked Mar 30 '11 04:03

Rob Lachlan


1 Answers

You can define something like:

(defn map-data [dataset column fn]
  (conj-cols (sel dataset :except-cols column)
             ($map fn column dataset)))

and use as

(def data (get-dataset :cars))
(map-data data :speed #(* % 2))

there is only one problem with changing of column names - I'll try to fix it, when I'll have free time...

like image 170
Alex Ott Avatar answered Sep 19 '22 17:09

Alex Ott