[R] Kruskal.test

arun smartpink111 at yahoo.com
Wed Jul 10 14:24:27 CEST 2013


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.rt at gmail.com>
To: arun <smartpink111 at 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



More information about the R-help mailing list