The apply function coerces the factor results to a character array
apply(g,2,class) # gives character

The kruskal.test function doesn't take character vector as the group
argument.
kruskal.test(as.character(plant.height) ~ as.character(g[,8])) #doesn't work
kruskal.test(plant.height ~ as.character(g[,8])) #doesn't work
kruskal.test(as.character(plant.height) ~ g[,8]) #works

You'd better change the kw function.
kw <- function(x) kruskal.test(plant.height ~ as.factor(x))$"p.value"

-----
A R learner.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Kruskal-Walllis-test-tp2311712p2312063.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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