试试这个:
set.seed(001) # Generating some data
DF <- data.frame(A1=sample(1:9, 10, T),
A2=sample(1:9, 10, T),
A3=sample(1:9, 10, T),
B1=sample(1:9, 10, T),
B2=sample(1:9, 10, T),
B3=sample(1:9, 10, T))
sampA <- DF[,grep('A', names(DF))] # Sample with columns A
sampB <- DF[,grep('B', names(DF))] # Sample with columns B
lapply(1:nrow(DF), function(i){
wilcox.test(as.numeric(sampA[i,]), as.numeric(sampB[i,]), exact=FALSE )
}) # Performing the test
结果如下所示:
[[1]]
Wilcoxon rank sum test with continuity correction
data: as.numeric(sampA[i, ]) and as.numeric(sampB[i, ])
W = 3, p-value = 0.6579
alternative hypothesis: true location shift is not equal to 0
[[2]]
Wilcoxon rank sum test with continuity correction
data: as.numeric(sampA[i, ]) and as.numeric(sampB[i, ])
W = 0, p-value = 0.0722
alternative hypothesis: true location shift is not equal to 0
[[3]]
Wilcoxon rank sum test with continuity correction
data: as.numeric(sampA[i, ]) and as.numeric(sampB[i, ])
W = 6, p-value = 0.6579
alternative hypothesis: true location shift is not equal to 0
我只显示了前 3 个结果,完整的列表长度为 10,因为DF
有 10 行。