Statistics test in R outputs many descriptions. While they are useful, how can we just output or extract single values?
> cor.test(x,y,method="spearman", exact=F)
Spearman's rank correlation rho
data: x and y
S = 12767993, p-value = 0.0001517
alternative hypothesis: true rho is not equal to 0
sample estimates:
rho
-0.188074
particularly, what to do to just get out these values 0.0001517 and -0.188074 so I can store them for further analyses?
You can use
$subsetting of the test object. The relevant names arep.valueandestimate..
Edit
The other answers point out that you can investigate the structure of the object with
strto find the names to use with$subsetting. You can also find out the names withnames:Another thing to consider is that you are looking at the printed version of the object, and the print method may be performing some calculations (it isn’t in this case). You can check the object class with
class(tst)which reveals it is of classhtest.print.htestis the relevant print method, but this is non-visible, so usegetAnywhere(print.htest)to view it.