Hi All
I have a vector in the following format:
[
["M" "3.4" "5.6"] ["L" "4.2" "6.6"] ["L" "4.9" "7.9"] ["L" "1.1"
"2.4"]["L" "5.4" "4.5"]
]
I would like to create a vector that contains the max values of each
of the second and third values from this vector
in this case it would be: [5.4, 7.9]
The method to do this that i have seen would be to
1. Transpose the vector using (apply map vector v)
2. Discard the vector of Ms and Ls
3 Cast all of the remaining numbers to Float
4 Apply Max to each of the vectors.
There *has* to be a more elegant way to do this than I have been
trying.
Any thoughts are appreciated as usual!
Base
****
(def v [["M" "3.4" "5.6"] ["L" "4.2" "6.6"] ["L" "4.9" "7.9"] ["L"
"1.1" "2.4"]["L" "5.4" "4.5"]])
(def v2 (rest (apply map vector v)))
(def f1 (map #(Float/parseFloat %) (first v2))
(def f2 (map #(Float/parseFloat %) (fnext v2))
(apply max f1)
(apply max f2)
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en