Hi, Please dput() your example dataset. dat1<- read.table(text="a a a a a b b b c c c c 2 4 5 2 7 2 2 6 3 7 9 3 3 3 4 1 6 8 1 3 5 2 6 3",sep="",header=FALSE,stringsAsFactors=FALSE) library(reshape) dat2<-melt(as.data.frame(t(dat1)),id.var="V1")[,-2] kruskal.test(value~V1,data=dat2) # # Kruskal-Wallis rank sum test # #data: value by V1 #Kruskal-Wallis chi-squared = 1.2888, df = 2, p-value = 0.525
#I guess you wanted for each row: lapply(split(dat2,(seq_len(nrow(dat2))-1)%/%ncol(dat1)+1),function(x) kruskal.test(value~V1,data=x)) #$`1` # # Kruskal-Wallis rank sum test # #data: value by V1 #Kruskal-Wallis chi-squared = 2.003, df = 2, p-value = 0.3673 # #$`2` # Kruskal-Wallis rank sum test #data: value by V1 #Kruskal-Wallis chi-squared = 0.1231, df = 2, p-value = 0.9403 A.K. ________________________________ From: Vera Costa <veracosta...@gmail.com> To: arun <smartpink...@yahoo.com> Sent: Wednesday, July 10, 2013 6:38 AM Subject: Re: Kruskal.test Thank you. And if I have a a a a a b b b c c c c 2 4 5 2 7 2 2 6 3 7 9 3 3 3 4 1 6 8 1 3 5 2 6 3 ? How can I apply the test by row? Thank you ______________________________________________ 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.