Please excuse my naive question.
I have a loop which returns in every step, a matrix b
.
I would like to save each matrix from each loop, under a different name depending on the iteration number. For example, at the end of the first iteration, I want to get the matrix named b1
, at the end of the second iteration the b2
etc...
As an example, lets use the following code:
count=0
a=matrix(c(1,2,3,4,5,6,7,8,9,10,11,12), nrow=6)
for (count in 1:10) {
b<-cbind(a[,1],matrix(c( a[sample(nrow(a)),2]), nrow=nrow(a)) )
print(b)
}
count+1
Here, the original matrix is matrix a
which has 6
rows and 2
columns.
I permute the order of the elements in the second column. The resulting matrix b
, is the matrix that conatins as first column the first column of the original matrix a
and as second column the permuted second column of a
.
Can anyone help me?