[R] Get output values in a table

Iurie Malai iurie.malai at gmail.com
Tue May 25 22:30:19 CEST 2010


Hi,

I use two similar scripts to put p-values of shapiro.test and, respectively,
of wilcox.test in a table:

a)
d <- data.frame(dataset$GroupFactor, dataset[2:11])
# p-values for the shapiro test (by levels of GroupFactor)
with(d, aggregate(d[,-1], list(d[,1]), FUN = function(x)
shapiro.test(x)$p.value))

b)
d <- data.frame(dataset$GroupFactor, dataset[2:11])
with(d, aggregate(d[,-1], list(d[,1]), FUN = function(x)
wilcox.test(x)$p.value))

How to replace the p-values with values of "W" (for Shapiro-Wilk test and,
respectively, for Wilcoxon-Mann-Whitney U test)?

Example of output:
---------------------------
> with(d, aggregate(d[,-1], list(d[,1]), FUN = function(x)
shapiro.test(x)$p.value))
  Group.1            1          2        3           4            5
6         7         8      IA        IV
1   town 0.0030465882 0.002068448 0.01129771 7.606061e-06 1.189380e-03
0.001396341 0.009097276 6.824918e-05 0.4877525 0.08005584
2   country 0.0002436141 0.005135004 0.01540923 2.469611e-06 1.372854e-05
0.001517259 0.052174738 1.057227e-06 0.3172002 0.15745973


Regards,
Iurie Malai
Department of Psychology
Ion Creanga Moldova Pedagogical State University - www.upsm.md
http://en.wikipedia.org/wiki/Ion_Creang%C4%83_Pedagogical_State_University
-------------- next part --------------
"GroupFactor",1,2,3,4,5,6,7,8,"IA","IV"
"town",7,5,4,5,5,8,6,8,5.30,7.00
"town",3,5,5,3,2,6,9,5,4.30,7.50
"town",7,5,8,0,3,10,9,5,6.60,9.50
"town",5,6,7,3,6,6,8,5,6.00,7.00
"town",6,7,7,5,5,7,8,8,6.60,7.50
"town",4,7,3,5,3,8,8,5,4.60,8.00
"town",5,5,7,4,5,10,8,8,5.60,9.00
"town",8,5,8,4,5,8,9,5,7.00,8.50
"town",9,7,8,4,5,5,8,3,8.00,6.50
"town",6,4,3,2,4,7,4,8,4.30,5.50
"town",3,5,4,2,6,5,9,7,4.00,7.00
"town",6,6,4,2,4,5,3,8,5.30,4.00
"town",6,6,8,4,6,8,9,7,6.60,8.50
"town",7,8,6,2,4,5,5,6,7.00,5.00
"town",2,6,5,4,6,10,7,9,4.30,8.50
"town",4,3,3,0,3,9,4,7,3.30,6.50
"town",7,6,5,3,3,6,8,4,6.00,7.00
"town",7,6,5,3,6,9,8,7,6.00,8.50
"town",7,5,9,4,4,5,3,4,7.00,4.00
"town",4,4,5,4,4,2,6,7,4.30,4.00
"town",5,3,8,2,4,10,11,7,5.30,10.50
"town",4,5,2,1,3,7,5,5,3.60,6.00
"town",5,6,7,2,5,7,5,7,6.00,6.00
"town",8,3,7,4,8,8,6,7,6.00,7.00
"town",4,2,2,4,2,4,6,6,2.60,5.00
"town",6,6,6,2,5,5,9,8,6.00,7.00
"town",6,6,8,3,7,8,10,6,6.60,9.00
"town",6,4,8,4,5,6,8,8,6.00,7.00
"town",2,2,4,3,3,5,6,2,2.60,5.50
"town",2,4,6,2,3,5,7,7,4.00,6.00
"town",2,4,2,2,2,5,5,7,2.60,5.00
"town",8,5,9,3,2,8,10,2,7.30,9.00
"town",7,6,5,3,3,8,9,4,6.00,8.50
"town",8,8,8,4,7,8,6,8,8.00,7.00
"town",4,3,8,5,7,5,8,3,5.00,6.50
"town",8,8,9,5,6,10,11,8,8.30,10.50
"town",3,3,4,0,1,5,5,4,3.30,5.00
"town",3,4,4,2,4,8,7,5,3.60,7.50
"town",5,5,5,5,4,7,5,2,5.00,6.00
"town",6,7,6,3,5,8,8,8,6.30,8.00
"town",5,3,5,4,5,7,4,8,4.30,5.50
"town",2,2,1,3,2,2,1,3,1.60,1.50
"town",5,6,7,1,5,6,3,4,6.00,4.50
"town",7,3,3,2,4,1,1,4,4.30,1.00
"town",6,1,8,1,6,6,7,5,5.00,6.50
"town",7,5,6,2,7,5,7,4,6.00,6.00
"town",4,6,9,2,4,4,6,5,6.30,5.00
"town",7,5,2,4,4,6,6,7,4.60,6.00
"town",5,3,8,3,5,5,4,2,5.30,4.50
"town",5,4,7,5,4,3,6,1,5.30,4.50
"town",5,6,4,1,6,8,9,7,5.00,8.50
"town",8,7,3,4,7,6,7,8,6.00,6.50
"town",7,4,4,5,4,6,7,4,5.00,6.50
"town",5,5,2,3,4,6,5,6,4.00,5.50
"town",4,1,3,2,2,6,4,8,2.60,5.00
"town",10,6,7,3,7,6,7,8,7.60,6.50
"town",6,3,3,3,4,8,8,4,4.00,8.00
"town",2,6,9,5,6,3,4,8,5.60,3.50
"town",8,4,5,2,4,6,9,4,5.60,7.50
"town",7,3,6,2,4,5,8,5,5.30,6.50
"town",7,5,6,4,4,5,6,1,6.00,5.50
"town",5,2,8,3,6,7,10,8,5.00,8.50
"town",4,5,4,3,5,8,8,7,4.30,8.00
"town",2,2,4,1,6,7,8,8,2.60,7.50
"town",4,4,7,5,2,6,6,6,5.00,6.00
"town",9,8,10,2,7,7,7,8,9.00,7.00
"town",5,6,4,4,2,8,5,5,5.00,6.50
"town",5,5,5,3,1,7,7,6,5.00,7.00
"town",7,3,5,4,6,9,8,7,5.00,8.50
"town",6,5,1,3,5,1,7,9,4.00,4.00
"town",5,5,5,2,1,7,6,6,5.00,6.50
"town",7,2,5,4,5,6,8,6,4.60,7.00
"town",8,8,7,5,4,7,11,6,7.60,9.00
"town",6,5,5,3,1,6,9,5,5.30,7.50
"town",5,6,6,5,4,4,8,2,5.60,6.00
"town",7,5,9,5,7,5,6,9,7.00,5.50
"town",5,7,3,2,3,7,8,8,5.00,7.50
"town",8,8,7,4,7,10,9,8,7.60,9.50
"town",9,6,7,5,7,7,9,6,7.30,8.00
"town",5,4,5,4,4,7,8,8,4.60,7.50
"town",6,3,5,5,7,5,5,5,4.60,5.00
"town",7,6,5,4,3,7,7,4,6.00,7.00
"town",8,6,6,5,1,3,7,7,6.60,5.00
"town",3,3,6,1,6,7,10,8,4.00,8.50
"town",6,4,8,2,5,7,7,6,6.00,7.00
"town",7,8,4,2,7,5,8,4,6.30,6.50
"town",8,7,7,5,7,8,7,9,7.30,7.50
"town",5,4,3,1,4,8,10,6,4.00,9.00
"town",4,4,2,4,4,5,6,5,3.30,5.50
"town",8,5,10,3,7,8,9,8,7.60,8.50
"town",6,1,2,4,3,3,4,5,3.00,3.50
"town",7,5,7,5,2,6,10,6,6.30,8.00
"town",3,5,4,1,3,6,6,5,4.00,6.00
"town",6,5,7,2,6,8,9,5,6.00,8.50
"town",6,5,7,2,4,6,7,7,6.00,6.50
"town",7,4,7,2,6,2,5,5,6.00,3.50
"town",8,3,7,4,4,5,7,7,6.00,6.00
"town",4,8,5,5,4,6,6,5,5.60,6.00
"town",9,8,10,4,8,9,10,7,9.00,9.50
"town",7,6,7,5,6,5,7,5,6.60,6.00
"country",6,8,6,4,7,8,8,9,6.60,8.00
"country",4,5,7,3,4,7,8,8,5.30,7.50
"country",7,5,7,3,6,7,9,4,6.30,8.00
"country",8,6,5,4,5,7,12,8,6.30,9.50
"country",2,4,3,3,4,6,6,9,3.00,6.00
"country",5,8,6,4,8,9,8,9,6.30,8.50
"country",7,6,9,4,7,9,10,7,7.30,9.50
"country",6,4,4,1,6,7,4,7,4.60,5.50
"country",5,3,1,2,8,4,5,7,3.00,4.50
"country",6,6,9,1,3,6,9,4,7.00,7.50
"country",6,3,7,4,7,10,10,9,5.30,10.00
"country",3,4,7,3,6,8,10,7,4.60,9.00
"country",6,3,3,4,6,7,11,8,4.00,9.00
"country",7,5,5,4,6,6,9,6,5.60,7.50
"country",7,4,4,1,6,8,7,6,5.00,7.50
"country",8,4,6,3,5,7,7,7,6.00,7.00
"country",7,4,4,1,4,9,9,6,5.00,9.00
"country",7,4,7,4,5,6,5,7,6.00,5.50
"country",6,3,7,5,7,6,5,9,5.30,5.50
"country",7,6,6,5,5,7,8,6,6.30,7.50
"country",5,1,6,1,6,7,2,7,4.00,4.50
"country",4,5,6,4,6,6,5,7,5.00,5.50
"country",3,3,5,2,4,6,6,5,3.60,6.00
"country",8,5,5,1,6,9,8,5,6.00,8.50
"country",4,3,4,1,1,4,7,6,3.60,5.50
"country",5,5,6,1,7,5,8,9,5.30,6.50
"country",6,5,3,3,7,7,8,7,4.60,7.50
"country",5,6,8,1,5,7,5,9,6.30,6.00
"country",3,8,5,4,7,4,6,7,5.30,5.00
"country",8,7,8,4,7,10,11,9,7.60,10.50
"country",5,3,3,4,4,7,9,5,3.60,8.00
"country",3,5,4,1,4,7,7,8,4.00,7.00
"country",7,1,6,2,3,6,4,6,4.60,5.00
"country",7,5,7,3,3,7,8,6,4.60,7.50
"country",3,2,6,1,4,11,4,5,3.60,7.50
"country",6,2,6,1,5,7,6,7,4.60,6.50
"country",4,4,4,0,5,10,6,5,4.00,8.00
"country",6,6,9,2,3,6,9,4,7.00,7.50
"country",3,2,4,3,7,9,9,5,3.00,9.00
"country",4,7,5,4,7,5,9,8,5.30,7.00
"country",6,5,6,4,5,8,9,7,5.60,8.50
"country",7,7,4,3,4,7,6,6,4.60,6.50
"country",6,4,5,2,4,6,6,9,5.00,6.00
"country",5,5,6,4,5,8,7,9,5.30,7.50
"country",9,3,4,2,6,9,7,8,5.30,8.00
"country",6,7,4,4,3,7,7,6,5.60,7.00
"country",7,4,7,2,8,7,7,9,6.00,7.00
"country",7,3,3,1,5,8,8,8,4.30,8.00
"country",2,6,5,4,7,10,8,9,4.30,9.00
"country",6,5,6,3,7,8,5,8,5.60,6.50
"country",3,4,1,0,5,6,5,9,2.60,5.50
"country",6,7,7,3,7,7,10,7,6.60,8.50
"country",2,2,3,3,3,6,4,5,2.30,5.00
"country",5,4,4,2,5,7,7,7,4.30,7.00
"country",7,4,4,2,5,6,8,7,5.00,7.00
"country",3,6,5,1,7,5,7,7,4.60,7.00
"country",6,3,3,4,6,6,7,8,4.00,7.50
"country",6,3,6,4,6,7,6,9,5.00,6.50
"country",6,7,5,2,5,7,9,7,6.00,8.00
"country",7,6,8,3,7,9,9,7,7.00,9.00
"country",7,4,5,2,7,6,5,7,5.30,5.50
"country",8,6,6,4,3,9,8,7,6.60,8.50
"country",6,4,4,4,3,4,6,6,4.60,5.00
"country",6,4,6,4,4,8,6,9,5.30,7.00
"country",5,9,7,5,7,7,10,9,7.00,8.50
"country",7,7,5,4,1,3,5,4,6.30,4.00
"country",6,2,5,3,1,6,7,5,4.30,6.50
"country",4,3,7,2,6,7,3,8,4.60,5.00
"country",6,6,7,1,7,8,8,6,6.30,8.00
"country",8,7,7,4,7,10,10,9,7.30,10.00
"country",5,3,5,1,6,7,10,5,4.30,8.50
"country",5,4,6,0,7,5,7,7,5.00,6.00
"country",5,2,4,2,4,10,5,8,3.60,7.50
"country",5,6,6,4,7,9,11,9,4.30,6.50
"country",4,5,7,4,6,8,7,9,5.60,10.00
"country",6,6,5,3,7,7,8,8,5.30,7.50
"country",3,3,1,2,5,9,5,9,5.60,8.00
"country",3,3,7,2,7,6,7,9,2.30,7.00
"country",4,7,6,2,4,5,6,8,5.60,5.50
"country",6,4,5,4,5,7,6,6,5.00,6.50
"country",6,7,5,2,7,6,5,8,6.00,5.50
"country",5,4,3,3,5,6,5,7,4.00,5.50
"country",6,6,8,3,6,8,8,9,6.60,8.00
"country",2,4,6,3,7,9,9,9,4.00,9.00
"country",9,4,10,3,5,7,8,9,7.60,7.50
"country",8,5,6,4,5,9,10,9,6.30,9.50
"country",3,5,8,2,7,6,10,8,5.30,8.00
"country",4,3,4,2,8,7,6,5,3.60,6.50
"country",6,5,6,3,3,7,8,7,5.60,7.50
"country",2,5,6,3,6,10,9,9,4.30,9.50
"country",3,3,5,1,6,6,8,8,3.60,7.00
"country",6,3,3,1,5,4,4,4,4.00,4.00
"country",6,5,2,4,3,7,6,8,4.30,6.50
"country",3,2,5,3,3,4,4,5,3.30,4.00
"country",6,2,3,1,5,6,5,6,3.60,5.50
"country",6,4,4,1,6,8,6,8,4.60,7.00
"country",6,2,9,5,6,7,7,7,5.60,7.00
"country",4,4,5,1,6,5,6,9,4.30,5.50
"country",8,6,7,4,6,7,6,5,7.00,6.50
"country",8,3,5,3,3,8,8,7,5.30,8.00


More information about the R-help mailing list