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

Richard M. Heiberger rmh @end|ng |rom temp|e@edu
Thu May 12 21:52:56 CEST 2022


you wrote
 mean(mlagFZ1,mlagFZ2,mlagFZ3)

you intended to write
 mean(c(mlagFZ1,mlagFZ2,mlagFZ3))
________________________________
From: R-help <r-help-bounces using r-project.org> on behalf of Sorkin, John <jsorkin using som.umaryland.edu>
Sent: Thursday, May 12, 2022 3:31:51 PM
To: r-help using r-project.org <r-help using r-project.org>
Subject: [External] [R] result of mean(v1, v2, v3) of three real number not the same as sum(v1, v2, v3)/3

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?
______________________________________________
R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C01%7Crmh%40temple.edu%7Cad57db1be49d481a7b8b08da344e1ce5%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637879807634239778%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=hFFO1S%2BKjqyVjjkiF%2BrI2WoqyYtbAL1eQNRCLWNZrGc%3D&reserved=0
PLEASE do read the posting guide https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=05%7C01%7Crmh%40temple.edu%7Cad57db1be49d481a7b8b08da344e1ce5%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637879807634239778%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=h7unlucyqKJ2yWZ2nqVhZWekHPRq%2FbeTBEy1OSKIfZ0%3D&reserved=0
and provide commented, minimal, self-contained, reproducible code.

	[[alternative HTML version deleted]]



More information about the R-help mailing list