Ivo, To be a bit clearer, your problem was not with mean(0 but with any function which is expecting a Boolean setting of TRUE/FALSE and instead got a nonsense value of 20.
This gets even weirder in languages which automagcally transform many other values to be considered true. Languages like C consider many non-zero values to be true, including 20 as an integer. A language like python accepts a very wide variety of things as truthy and the few that qualify as falsy are empty strings, and zero as well as other empties like an empty list, empty dictionary, empty set, empty range, or even a complex number with both a zero real and imaginary part. Some see such designs as saving lots of labor and others suggest it would be better and clearer programming practice to only accept explicit code that is guaranteed to produce a Boolean such as is_empty(list) or whatever. In this case, it is simply fairly poor design to alias T/F to TRUE/FALSE for convenience and then have people inadvertently reuse the variables and produce odd results. In languages which support constants that can be set and protected from change, fine. But in R, I never use T/F as the longer versions are clearer and less error prone. I don't blame you for being teed off at why things where not working when T was redefined. -----Original Message----- From: R-help <r-help-boun...@r-project.org> On Behalf Of Ivo Welch Sent: Thursday, December 12, 2024 7:23 PM To: r-help@r-project.org Subject: [R] Weird Behavior of mean 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@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. ______________________________________________ R-help@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.