R – output p value from a t-test in R

p-valuer

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

Best Answer

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
Related Topic