Using each
in plyr, the first two each
commands work without error, but the third one produces the error
Error: Results must have the same dimensions.
The only difference in the three each
commands is in the third argument ("mode"=...)
library(plyr)
each("mean"=function(x) ifelse(is.numeric(x),mean(x),NA)
, "median"=function(x) ifelse(is.numeric(x), median(x), NA)
, "mode"=function(x) names(which.max(table(x))))
each("mean"=function(x) ifelse(is.numeric(x),mean(x),NA)
, "median"=function(x) ifelse(is.numeric(x), median(x), NA)
, "mode"=function(x) ifelse(TRUE, names(which.max(table(x))), NA))
each("mean"=function(x) ifelse(is.numeric(x),mean(x),NA)
, "median"=function(x) ifelse(is.numeric(x), median(x), NA)
, "mode"=function(x) ifelse(is.factor(x), names(which.max(table(x))), NA))
I fail to understand why.