Why can't this function be used with the 'by' command?

> x = array(runif(16), dim=c(8,2))
> x = data.frame(x)
> x$group = rep(c('wt', 'app'), each=4)

> shapiro.p = function(x) shapiro.test(x)[[2]]
> apply(x[,1:2], 2, shapiro.p)
       X1        X2
0.4126345 0.2208781

> by(x[,1:2], x$group, shapiro.p)
Error in `[.data.frame`(x, complete.cases(x)) :
  undefined columns selected

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to