Ivan Krylov
2022-May-12 19:41 UTC
[R] result of mean(v1, v2, v3) of three real number not the same as sum(v1, v2, v3)/3
On Thu, 12 May 2022 19:31:51 +0000 "Sorkin, John" <jsorkin at som.umaryland.edu> wrote:> > mean(mlagFZ1,mlagFZ2,mlagFZ3) > [1] -0.3326792match.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
Eric Berger
2022-May-12 19:44 UTC
[R] result of mean(v1, v2, v3) of three real number not the same as sum(v1, v2, v3)/3
Or ... to put it differently,, you need to wrap the numbers in c( .., .., ) On Thu, May 12, 2022 at 10:42 PM Ivan Krylov <krylov.r00t at gmail.com> wrote:> On Thu, 12 May 2022 19:31:51 +0000 > "Sorkin, John" <jsorkin at 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 > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Sorkin, John
2022-May-12 19:45 UTC
[R] result of mean(v1, v2, v3) of three real number not the same as sum(v1, v2, v3)/3
Ivan, Thank you for your quick reply. Unfortunately, I don't understand the concept you are trying toe explain. Can you try again? Thank you, John ________________________________________ From: Ivan Krylov <krylov.r00t at gmail.com> Sent: Thursday, May 12, 2022 3:41 PM To: Sorkin, John Cc: r-help at r-project.org Subject: Re: [R] result of mean(v1, v2, v3) of three real number not the same as sum(v1, v2, v3)/3 On Thu, 12 May 2022 19:31:51 +0000 "Sorkin, John" <jsorkin at som.umaryland.edu> wrote:> > mean(mlagFZ1,mlagFZ2,mlagFZ3) > [1] -0.3326792match.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