Hello,
Try the following.
mySD <- function(x) {sapply(x, function(y) sqrt(var(y)))}
Hope this helps,
Rui Barradas
Citando John Sorkin :
> I am trying to use the by function to get the SD of each column of
> a data frame, stratified by ARM. Using a suggestion
I am trying to use the by function to get the SD of each column of a data
frame, stratified by ARM. Using a suggestion provided by both William Dunlap
and Rolf Turner, I have written the code below which fails with the error:
Error in match.fun(FUN) : 'sqrt(var(x))' is not a function,
sapply's FUN argument must be a function (or a character string naming
a function) and sqrt(var(x)) evaluates to a number, not a function.
mySD <- function(x) {sapply(x,function(x)sqrt(var(x)))}
would work, but I like to make it
mySD <- function(x) {sapply(x,function(xi)sqrt(var(xi)))}
to make
3 matches
Mail list logo