[R] Weird Behavior of mean
CALUM POLWART
po|c1410 @end|ng |rom gm@||@com
Fri Dec 13 09:56:15 CET 2024
I've not checked the code, but I think that result would happen if mean
uses something like
if (na.rm == TRUE) {
# do something to remove the NA's
}
And as uses something like
If (na.rm != FALSE) {
# do something to remove the NA's
}
Or perhaps ever na.rm == T
If you ever see posts from Bert on here with T and F, he is hard core
thorough and uses full words for exactly this reason, someone can reassign
F as True if they want and your code will melt!
On Fri, 13 Dec 2024, 08:31 Ivo Welch, <ivo.welch using gmail.com> wrote:
> Is the following a strange behavior for `mean` vs. `sd` ?
>
> ```
> $ R --vanilla. ## 4.4.2
> > x=c(NA,1,2,3)
> > c( mean(x,na.rm=T), sd(x,na.rm=T) )
> [1] 2 1
> > T=20 ## bad idea for a parameter. T is also used for TRUE
> > c( mean(x,na.rm=T), sd(x,na.rm=T) )
> [1] NA 1
> >
> ```
>
> This one was a baffler for me to track down for a few hours...
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> https://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list