我已生成以下列表,我只想提取cor值(最后一个值)。有没有办法做到这一点?我尝试使用$ estimate来做到这一点,但无济于事。在此先感谢您的帮助。
[[6]]
Pearson's product-moment correlation
data: cer[, x] and par[, y]
t = 109.0053, df = 1898, p-value < 2.2e-16
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.9221188 0.9345283
sample estimates:
cor
0.9285826 #this value
str(list)的输出:
$ :List of 9
..$ statistic : Named num 68.5
.. ..- attr(*, "names")= chr "t"
..$ parameter : Named int 1898
.. ..- attr(*, "names")= chr "df"
..$ p.value : num 0
..$ estimate : Named num 0.844
.. ..- attr(*, "names")= chr "cor"
..$ null.value : Named num 0
.. ..- attr(*, "names")= chr "correlation"
..$ alternative: chr "two.sided"
..$ method : chr "Pearson's product-moment correlation"
..$ data.name : chr "cer[, x] and par[, y]"
..$ conf.int : atomic [1:2] 0.83 0.856
.. ..- attr(*, "conf.level")= num 0.95
..- attr(*, "class")= chr "htest"
答案 0 :(得分:3)
&LT; mind.read&gt;
您似乎提供了一个包含结果的列表
cor.test(..., method = 'pearson')
&LT; \ mind.read&gt;
如果此列表名为z
然后
sapply(z, '[[', 'estimate')
将从estimate
z
元素
记住财富(312)
很有用fortune(312)
The problem here is that the $ notation is a magical shortcut and like any other
magic if used incorrectly is likely to do the programmatic equivalent of turning
yourself into a toad.
-- Greg Snow (in response to a user that wanted to access a column whose name is
stored in y via x$y rather than x[[y]])
R-help (February 2012)