Here’s a weird R error/bug/nuance I came across today:
What would you expect the following lines of code to return?
x = c('1', '2', '3')
Well, apparently it is:
sd() silently converts its input to numeric, while
mean() does not. More evidence of this is in the source:
function (x, ...)
function (x, na.rm = FALSE)
sqrt(var(if (is.vector(x)) x else as.double(x), na.rm = na.rm))
One hour of my work day was spent sorting this out. You’ve been warned.
Written with StackEdit.