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]]

