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.
Asked
Active
Viewed 223 times
1 Answers
1
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.

Ankur
- 33,367
- 2
- 46
- 72
-
Thank you for your reply. I should explain my dilemma better. Using the 2 arg function & example I would have to try something like this: (fn [f1 f2] (do (/ f1 20) (/ f2 20))) [:fq1 :fq2] freqs, which returns only a modified :fq2 column. My problem is more general in that I also need to do the / for perhaps 2, 3, 4 or more columns depending on the number of data columns. – Brian Apr 15 '13 at 19:47
-
You can return a vector from the function .. (fn [f1 f2] [(/ f1 20) (/ f2 20)]) – Ankur Apr 16 '13 at 04:04
-
Thanks for this clarification to my syntax; much appreciated. Hopefully the incanter documentation improves over the years. – Brian Apr 16 '13 at 12:04