David Winsemius
On Jan 12, 2009, at 12:07 PM, rafamoral wrote:
>
> 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.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.