[R] result of mean(v1, v2, v3) of three real number not the same as sum(v1, v2, v3)/3
Marc Schwartz
m@rc_@chw@rtz @end|ng |rom me@com
Thu May 12 21:47:40 CEST 2022
Hi John,
sum() takes an arbitrary "..." list as the initial argument, while mean() takes a vector "x" as the initial named argument.
Thus:
> sum(-0.3326792, -0.1890601, -0.0840866) / 3
[1] -0.201942
> mean(c(-0.3326792, -0.1890601, -0.0840866))
[1] -0.201942
Regards,
Marc Schwartz
On May 12, 2022 at 3:31:51 PM, Sorkin, John (jsorkin using som.umaryland.edu (mailto:jsorkin using som.umaryland.edu)) wrote:
> I have a very strange problem. I am getting different results from
> mean(mlagFZ1,mlagFZ2,mlagFZ3)
> vs.
> sum(mlagFZ1,mlagFZ2,mlagFZ3)/3
>
>
> > mean(mlagFZ1,mlagFZ2,mlagFZ3)
> [1] -0.3326792
>
> > sum(mlagFZ1,mlagFZ2,mlagFZ3)/3
> [1] -0.201942
>
> R code:
> print(mlagFZ1)
> print(mlagFZ2)
> print(mlagFZ3)
> sum(mlagFZ1,mlagFZ2,mlagFZ3)/3
> mean(mlagFZ1,mlagFZ2,mlagFZ3)
>
> output;
> > print(mlagFZ1)
> [1] -0.3326792
> > print(mlagFZ2)
> [1] -0.1890601
> > print(mlagFZ3)
> [1] -0.0840866
> > sum(mlagFZ1,mlagFZ2,mlagFZ3)/3
> [1] -0.201942
> > mean(mlagFZ1,mlagFZ2,mlagFZ3)
> [1] -0.3326792
>
> Can someone tell me what I did wrong?
More information about the R-help
mailing list