[R] writing autocorrelation and partial auto correlation functions to a file
Glen Barnett
glnbrntt at gmail.com
Thu May 20 11:51:14 CEST 2010
The problem is that the acf function (like many R functions) returns a list
containing many different things. For example, I have a short series in
the vector z:
> acz <- acf(z)
> str(acz)
List of 6
$ acf : num [1:11, 1, 1] 1 -0.0668 -0.7401 0.0627 0.5954 ...
$ type : chr "correlation"
$ n.used: int 11
$ lag : num [1:11, 1, 1] 0 1 2 3 4 5 6 7 8 9 ...
$ series: chr "z"
$ snames: NULL
- attr(*, "class")= chr "acf"
Let's say you are interested in extracting the acf and lag values from that
> acd <- data.frame(cbind(lag=acz$lag,acf=acz$acf))
> acd
lag acf
1 0 1.00000000
2 1 -0.06676557
3 2 -0.74006273
4 3 0.06266564
5 4 0.59542482
6 5 -0.06786556
7 6 -0.41370293
8 7 0.03464621
9 8 0.21887326
10 9 -0.07485743
11 10 -0.04835570
More information about the R-help
mailing list