Re: [R] error using by(goop[, c("a", "b", "c")], goop[, "Arm"], mySD) was Re: by gives no results, gives warning that data are non-numeric, but the data appears to be numeric.

2015-12-28 Thread ruipbarradas
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

[R] error using by(goop[, c("a", "b", "c")], goop[, "Arm"], mySD) was Re: by gives no results, gives warning that data are non-numeric, but the data appears to be numeric.

2015-12-28 Thread 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 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,

Re: [R] error using by(goop[, c("a", "b", "c")], goop[, "Arm"], mySD) was Re: by gives no results, gives warning that data are non-numeric, but the data appears to be numeric.

2015-12-28 Thread William Dunlap via R-help
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