我有 data.frame df1
:
set.seed(12345)
df1 <- data.frame(group=c(rep("apple", 4), rep("pear",6)), a=rnorm(10,0,0.4),
b=rnorm(10,0,0.2),
c=rnorm(10,0,0.7), d=rnorm(10,0,0.9), e=rnorm(10,0,0.5))
如何获得比较苹果(第 1:4 行)和梨(第 5:10 行)的列方式 wilcox.test p 值,并将该 p 值添加到底部的新行,从而得到 df2:
df2 <- data.frame(group=c(rep("apple", 4), rep("pear",6), "wilcox.test"),
a=c(rnorm(10,0,0.4), 0.393768635), b=c(rnorm(10,0,0.2), 0.286422023),
c=c(rnorm(10,0,0.7), 1), d=c(rnorm(10,0,0.9), 0.033006258),
e=c(rnorm(10,0,0.5), 1))
> df2
group a b c d e
1 apple 0.23421153 -0.02324956 0.5457353 0.73068586 0.5642554
2 apple 0.28378641 0.36346241 1.0190496 1.97715019 -1.190179
3 apple -0.04372133 0.07412557 -0.4510299 1.8442713 -0.5301328
4 apple -0.18139887 0.10404329 -1.0871962 1.46920108 0.4685703
5 pear 0.24235498 -0.1501064 -1.1183967 0.22884407 0.4272259
6 pear -0.72718239 0.16337997 1.2635683 0.44206945 0.7303647
7 pear 0.25203942 -0.1772715 -0.3371532 -0.29167792 -0.7065494
8 pear -0.11047364 -0.06631552 0.4342659 -1.49584522 0.2837016
9 pear -0.1136639 0.22414253 0.4284864 1.59096047 0.2915938
10 pear -0.3677288 0.05974474 -0.1136177 0.02322094 -0.6533994
11 wilcox.test 0.393768635 0.286422023 1 0.033006258 1