Re: [R] storing output of a loop in a matrix

2012-05-23 Thread Rainer Schuermann
Try for( i in 1:10 ){ ... } That should resove your problem 1.! Rgds, Rainer On Wednesday 23 May 2012 09:23:04 RH Gibson wrote: > "blap.txt" is a numeric vector of length 64. > > I am using the following code: > > > bd<-scan("blap.txt") > output<-matrix(0,64,10) > s<-sum(bd) > for (i in 10

Re: [R] storing output of a loop in a matrix

2012-05-23 Thread Petr PIKAL
Hi What is your intention? basically one output column can be made by cumsum(bd) Then you can shuffle bd by let say bd <- sample(bd, 64) and repeat cumsum for new bd. bd<-scan("blap.txt") output<-matrix(0,64,10) for (i in 1:10) { bd<-sample(bd, 64) cs<-cumsum(bd) output[,i]<-cs } If you in

[R] storing output of a loop in a matrix

2012-05-23 Thread RH Gibson
"blap.txt" is a numeric vector of length 64. I am using the following code: bd<-scan("blap.txt") output<-matrix(0,64,10) s<-sum(bd) for (i in 10){ while (s>0) {x1<-sample(bd,(length(bd)-1), replace=F) s<-sum(x1) bd<-x1 output[i]<-s } } write.table(output, file="res.txt") This code is not do