output p value from a t-test in R

2019-07-09 12:08发布

问题:

So lets work through the example from ?t.test()

We do a two-sample t-test on the data by:

t.test(1:10, y = c(7:20))

Now I am only interested in saving the p-value When I input the followng code, the $p.value is also saved.

t.test(1:10, y = c(7:20))[3]

I want only the p-value saved (with the $p.value) as an numeric/integer/double. Sorry for asking such a simple question

回答1:

You can save the p-value from the t-test to another variable with something like:

pVal <- t.test(1:10, y = c(7:20))$p.value

pVal will then be numeric:

> str(pVal)
num 1.86e-05


标签: r p-value