[R] result of mean(v1, v2, v3) of three real number not the same as sum(v1, v2, v3)/3

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Thu May 12 21:41:45 CEST 2022


On Thu, 12 May 2022 19:31:51 +0000
"Sorkin, John" <jsorkin using som.umaryland.edu> wrote:

> > mean(mlagFZ1,mlagFZ2,mlagFZ3)  
> [1] -0.3326792

match.call(mean.default, quote(mean(mlagFZ1, mlagFZ2, mlagFZ3)))
# mean(x = mlagFZ1, trim = mlagFZ2, na.rm = mlagFZ3)

mean() takes a vector to compute a mean of and additional arguments,
unlike sum(), which takes ... (almost arbitrary arguments) and sums all
of them. Unfortunately, the "trim" argument is documented to accept any
number and the na.rm argument is silently reinterpreted as logical in
your case.

-- 
Best regards,
Ivan



More information about the R-help mailing list