[R] Why can't this function be used with the 'by' command?
R. Michael Weylandt
michael.weylandt at gmail.com
Fri Nov 4 03:32:52 CET 2011
I believe it has to do with passing multiple columns to the
shapiro.test. Note that
by(x[,1:2], x$group, function(x) shapiro.test(x)[[2]])
doesn't work but
by(x[,1:2], x$group, function(x) shapiro.test(x[,1])[[2]])
does.
Michael
On Thu, Nov 3, 2011 at 8:08 AM, Kaiyin Zhong <kindlychung at gmail.com> wrote:
> 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 at 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.
>
More information about the R-help
mailing list