这就是我想要做的事情:
x <- c(1,2,3,3,2,3,4,5,6)
my_acf = acf(x,plot=F)
> my_acf
Autocorrelations of series ‘x’, by lag
0 1 2 3 4 5 6 7 8
1.000 0.497 0.097 -0.047 -0.050 -0.075 -0.231 -0.376 -0.316
我想只提取0.497,即第一个滞后的相关系数,我希望将其作为数值。我怎么能这样做?
谢谢
答案 0 :(得分:12)
答案是使用my_acf$acf[2]
。以下是我的解决方案:
> attributes(my_acf)
$names
[1] "acf" "type" "n.used" "lag" "series" "snames"
$class
[1] "acf"
> my_acf$acf
, , 1
[,1]
[1,] 1.00000000
[2,] 0.49747475
[3,] 0.09722222
[4,] -0.04734848
[5,] -0.04987374
[6,] -0.07512626
[7,] -0.23106061
[8,] -0.37563131
[9,] -0.31565657
> my_acf$acf[2]
[1] 0.4974747
答案 1 :(得分:1)
您可以尝试这样
my_acf$acf