Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert output from multiple t.tests to data frame

Tags:

r

I have performed a t-test on all my rows in my data frame which outputs alot of p-values. How could I get out the p-values in data.frame format together with the row.name that was the basis for the test?

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

All my p-values are stored in out2 in the following formatting:

$`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 

I would like to have something like:

rowname                      pvalue
$`hsa-let-7a-5p.dataSerum`   p-value < 2.2e-16
like image 866
user2300940 Avatar asked Jun 10 '26 12:06

user2300940


1 Answers

The output of t.test by row is a list. So, we can use one of the methods to extract values from the list. Either sapply/lapply/vapply can be used

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

set the names of 'v1' as the names of the 'out2'

names(v1) < names(out2)

The above output is vector. If we need a data.frame, wrap it with as.data.frame

as.data.frame(v1)
like image 103
akrun Avatar answered Jun 12 '26 10:06

akrun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!