Hi huys : I want to map a “average” for all values in a map. say I have a list of maps :
[{"age" 2 "height" 1 "weight" 10},
{"age" 4 "height" 4 "weight" 20},
{"age" 7 "height" 11 "weight" 40}]
And my desired output is
{"age 5 "height" 5 ....}
///Below are the ramblings of my brain, i.e. the way I might imagine this working in Clojure…not to be taken too seriously
transpose the list :
{"age" [2 4 7] "height" [1 4 11] }
and then I could simply do something like (again, making up a function called freduce here)
(freduce average (vals (map key-join list)))
to get
{"age" 5 "weight" 10 "height" 7}
Here’s a fairly verbose solution. Hopefully someone can come up with something better: