[R] Help with storage of each matrix generated in a loop

rafamoral rafa_moral2004 at yahoo.com.br
Mon Jan 12 18:07:06 CET 2009


I need to store each matrix generated in a loop.

I've been working with the CUSUM algorithm and I've been trying to implement
it in R.
What I need to do with my dataset is to create 1000 randomized datasets and
cumulative sum them all and store all of those randomized CUSUMed datasets
for further analysis and creation of the simulation envelope in the CUSUM
chart. But I can't manage to store all of them, the script I've written only
stores the last randomized matrix in the variable I called "cusumA".

Here's the script I've written:

mat <- matrix(data=rep(c(1,2,3,4,5), 16), nrow=16, ncol=5)
# The matrix that will be sampled
A <- matrix(data=0, nrow=16, ncol=5)
# The variable that will store the sampled matrix
for(i in 1:1000) {
# I want to do it 1000 times
for(j in 1:nrow(mat)) {
# The number of rows to be sampled)
A[j,] <- sample(mat[j,])
# The sample itself - I want to do it 1000 times and then...
cusumA <- cumsum(data.frame(A))
# cumulative sum it, and store the 1000 randomized matrices
}}

I've already tried to store it in a null matrix but it will only store the
first column of each matrix, so all I got was 1000 first columns. The code I
used to do it was

mat <- matrix(data=rep(c(1,2,3,4,5), 16), nrow=16, ncol=5)
A <- matrix(data=0, nrow=16, ncol=5)
cusumA <- matrix()
for(i in 1:1000) {
for(j in 1:nrow(mat)) {
A[j,] <- sample(mat[j,])
cusumA[i] <- cumsum(data.frame(A))
}}

and I even got 50+ warnings...
Any help'd be really appreciated!
-- 
View this message in context: http://www.nabble.com/Help-with-storage-of-each-matrix-generated-in-a-loop-tp21418758p21418758.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list