Question

Assume an incanter dataset, freqs, of k columns of integers. I want to convert say 2 of the columns into values between 0 to 1 by dividing each column value by a fixed value, say 20. I can do this using the $map function for 1 column: ($map (fn [x] (/ x 20)) :fq1 freqs ). The incanter documentation on $map seems to suggest that a vector of columns can be used: "...mapping the given function over the value(s) for the given column key(s) ...". However my attempts to do this ($map (fn [x] (/ x 20)) [:fq1 :fq2] freqs ) gives "a wrong number of args" area. I understand this error. Hopefully someone can say for sure if the use of a vector of column keys can be used with $map; if yes, an example would be a great help.

Was it helpful?

Solution

The incanter doc for $map shows that you can pass vector of column to $map and hence your code becomes:

($map (fn [f1 f2] (do-something-with f1 f2) [:fq1 :fq2] freqs) 

NOTE: As you are mapping over 2 columns, the function should take 2 params,also the wrong number of params is not because of the way you called $map, but rather your passed function is only taking one param.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top