将多个t.tests的输出转换为数据帧

时间:2016-02-04 07:17:24

标签: r

我对数据框中的所有行执行了t检验,输出了很多p值。我怎样才能得到data.frame格式的p值以及作为测试基础的row.name?

out2 <- apply(BindTissueSerumSort, 1, t.test, alternative = "greater")

我的所有p值都按以下格式存储在out2中:

$`hsa-let-7a-5p.dataSerum`

    One Sample t-test

data:  newX[, i]
t = 10.747, df = 72, p-value < 2.2e-16
alternative hypothesis: true mean is greater than 0
95 percent confidence interval:
 1.081222      Inf
sample estimates:
mean of x 
 1.279618 

我希望有类似的东西:

rowname                      pvalue
$`hsa-let-7a-5p.dataSerum`   p-value < 2.2e-16

1 个答案:

答案 0 :(得分:2)

t.test的输出为list。因此,我们可以使用其中一种方法从列表中提取值。可以使用sapply/lapply/vapply

v1 <- sapply(out2, function(x) x$p.value)

设置&#39; v1&#39;的名称作为&#39; out2&#39;

的名称
names(v1) < names(out2)

以上输出为vector。如果我们需要data.frame,请使用as.data.frame

进行换行
as.data.frame(v1)