Skip to content

Kruskal.test

1 message · arun

#
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.