I have am trying to obtain the average of the distance from the mean radius for each shot in a group of shots at a target. I am having problems with the very last line. The output of the last line appears that the Apply statement is being applied to the correct level but it is not resolving.
code
ShotsPerGroup = 3
NumberGroups = 2
(* Define the group of shots as a random variable with a normal distribution *)
RandomSeed[66936, Method -> All]
R := RandomVariate[NormalDistribution[]];
a = Flatten[
Table[List[i, R], {i, 1, NumberGroups}, {j, 1, ShotsPerGroup}],
1];
Print["a = ", TableForm[a]]
(* Group the shots by group *)
byGroup = GatherBy[a, First][[All, All, 2]];
Print["byGroup =", byGroup]
(* Calculate the distance from the mean radius of each shots by group *)
mr = Sqrt[(#^2 + Mean[#]^2)] & /@ byGroup
Print["mr = ", TableForm[mr]]
(* obtain the mean of the group mean radius *)
meanMR =
Apply[Mean, Sqrt[(#^2 + Mean[#]^2)] & /@ byGroup, 1]
output from last line:
{Mean[1.1711, 0.717469, 0.980774], Mean[0.631837, 1.55101, 0.573568]}
Apply
matchesmr
. Why not just stick that in? You are also confusing the use cases ofMap
(short form -/@
) andApply
.meanMR = Mean /@ mr
returns{1.64748, 1.13594}
. $\endgroup$