Hi Nico,
You are not referencing the array correctly I think - I am not working too much with arrays - the below works:
> for (t in T[1:(length(T)-n)]){
+ X[,,t] = cor(TS[t:(t+n), 1:ncol(TS)], use = "pairwise.complete.obs")}
Also note that your parameter T is unused & the X array will only be filled partially (1830 out of 1860, since you are using 30 to calculate your rolling correls - but X is still 1860 nrows)
HTH,
JC
> From: rstatistics.user@gmail.com
> Date: Fri, 31 Aug 2012 17:55:43 +0200
> To: r-sig-finance@stat.math.ethz.ch
> Subject: [R-SIG-Finance] Creating an array from correlation matrices
>
> Hello everyone,
>
> a hopefully easy to solve problem from an R novice...
>
> I try to calculate a number of correlation matrices that finally should be combined in a three-dimensional array.
>
>
> Here the my code with an R dataset as an example.
>
> ## Creation an array of correlation matrices from a rolling window application
>
> TS <- EuStockMarkets
> # Load internal dataset
>
> n <- 30
> # Choose size of rolling time window
>
> T <- c(1:nrow(TS))
> # Define number of steps
>
> X <- array(data = NA, dim = c(ncol(TS), ncol(TS), nrow(TS)))
> # Create data array
>
> for (t in T[1:(length(T)-n)]){
> X[t] = cor(TS[t:(t+n), 1:ncol(TS)], use = "pairwise.complete.obs")
> }
> # Calculate correlation matrices
>
>
> Unfortunately, I only get a warning that the dimensions do not fit... Where is the mistake?
>
> THANKS A LOT!
>
> Nico
> _______________________________________________
> R-SIG-Finance@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
[[alternative HTML version deleted]]