I'd like to get the Min, Max, Median, Mean, etc. for the same list. For now I'm doing the following:
y = {1, 2, 3, 4, 5, 6, 7};
Map[{Max[#] , Min[#] , Median[#], Mean[#]} &, y, {0}]
It seems like there should be a better way, not that this is awful. Is there a cleaner way to do this?
Answer
Also,
y = {1, 2, 3, 4, 5, 6, 7};
#[y] & /@ {Max, Min, Median, Mean}
(* {7, 1, 4, 4} *)
EDIT: comparing the timings:
n = 100000;
Do[Through[{Max, Min, Median, Mean}[y]], n] // AbsoluteTiming
(* {0.548089, Null} *)
Do[#[y] & /@ {Max, Min, Median, Mean}, n] // AbsoluteTiming
(* {0.709574, Null} *)
Through
is more efficient, at least in this case.
Comments
Post a Comment