在R中使用mapply时,将t.test的输出保存到数据帧

soo*_*sus 4 statistics r

我有两个这样的数据帧

a    b    c
1    2    3
2    3    3
1    2    3
Run Code Online (Sandbox Code Playgroud)

具有相同的列名称.我正在使用

mapply(t.test, df1, df2)
Run Code Online (Sandbox Code Playgroud)

输出t.text的结果,比较两个数据帧之间的a,b和c型列.这得到(实际结果):

        LHM                                      
statistic   -11.5671                                 
parameter   90.46322                                 
p.value     1.575918e-19                             
conf.int    Numeric,2                                
estimate    Numeric,2                                
null.value  0                                        
alternative "two.sided"                              
method      "Welch Two Sample t-test"                
data.name   "dots[[1L]][[23L]] and dots[[2L]][[23L]]"
        RaM                                      
statistic   -18.66368                                
parameter   172.2032                                 
p.value     3.200675e-43                             
conf.int    Numeric,2                                
estimate    Numeric,2                                
null.value  0                                        
alternative "two.sided"                              
method      "Welch Two Sample t-test"                
data.name   "dots[[1L]][[24L]] and dots[[2L]][[24L]]"
Run Code Online (Sandbox Code Playgroud)

等等(每个数据帧中有~180列数据).我需要将列的名称及其对应的p值存储在矩阵中.将哪个数据框包含较高值存储在另一列中也是有帮助的.救命?

Aru*_*run 5

试试这个:

mapply(function(x, y) t.test(x,y)$p.value, df1, df2)
# on my sample(/dummy) data.frames
#           a           b           c 
# 0.009963864 0.009963864 0.020204103 
Run Code Online (Sandbox Code Playgroud)

stack如果你想要一个data.frame像这样的2列格式,你可以把它包起来:

stack(mapply(function(x, y) t.test(x,y)$p.value, df1, df2))
#        values ind
# 1 0.009963864   a
# 2 0.009963864   b
# 3 0.020204103   c
Run Code Online (Sandbox Code Playgroud)