[R] accessing information in lists

Peter Wolf s-plus at wiwi.uni-bielefeld.de
Thu Apr 29 10:04:29 CEST 2004


Try:

<<*>>=
rev.matrix<-matrix(rnorm(40),10,4)
rev.acf<-apply(rev.matrix, 2, acf, na.action=na.contiguous, lag.max=12, 
plot=FALSE)
x.acf<-lapply(rev.acf,function(x) x[["acf"]][,,1])
matrix(unlist(x.acf),ncol=4)

output-start
Thu Apr 29 09:56:22 2004
             [,1]         [,2]        [,3]        [,4]
 [1,]  1.00000000  1.000000000  1.00000000  1.00000000
 [2,] -0.18009242 -0.066131687 -0.19268167 -0.25340270
 [3,] -0.15442666 -0.342732543 -0.30959136 -0.11987720
 [4,]  0.14785268  0.074751553  0.16748753 -0.16495692
 [5,] -0.34024505  0.210414077 -0.03338385  0.25205651
 [6,] -0.05562243  0.044047730  0.02971677 -0.05640866
 [7,]  0.09955468 -0.358754179 -0.02301302 -0.11177397
 [8,]  0.01609530  0.072731988 -0.16732203 -0.25562259
 [9,] -0.04621386 -0.005510738 -0.13049985  0.23890998
[10,]  0.01309776 -0.128816203  0.15928749 -0.02892446
output-end

BTW -- do not use  the name  t  for a variable, parameter, etc. because
there is a function  t().

Peter Wolf

Murray Keir wrote:

>I've created a dataframe containing multiple ACF lists through the command
>
>rev.acf<-apply(rev.matrix, 2, acf, na.action=na.contiguous, lag.max=12, plot=FALSE)
>
>where rev.matrix is an n by t matrix containing n time series in columns.  I'd now like to pull out only the ACF information and store it in a seperate n by 12 matrix.  So far the only way I can work out to access this is 
>
>rev.acf[["series1"]][["acf"]]
>rev.acf[["series2"]][["acf"]]
>etc
>
>Is there some way I can do this automatically?
>
>Thanks
>Murray
>
>
>
>
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>  
>




More information about the R-help mailing list