evt
evt

Reputation: 971

How do I pull out a specific component of the output of a function in R?

I am using the t.test() function. The output has a component "p.value" which I would like direct access to. For example, I would like to be able to append this p.value to a list.

Your advice is very much appreciated.

Upvotes: 0

Views: 254

Answers (1)

BrodieG
BrodieG

Reputation: 52637

The return value of t.test is just a list:

t.test(runif(10))$p.value
# [1] 0.0001406559

Also, here are the other things you can pull out:

names(t.test(runif(10)))
# [1] "statistic"   "parameter"   "p.value"     "conf.int"    "estimate"    "null.value" 
# [7] "alternative" "method"      "data.name"  

Upvotes: 2

Related Questions