[R] Re : adding columns to a table after a loop

John Kane jrkrideau at yahoo.ca
Sat Aug 12 19:30:33 CEST 2006


--- Albert Picado <albert_picado at yahoo.fr> wrote:

Albert 

> Dear Uwe,
>  
> Thanks for your answer. 

----clip

> De : Uwe Ligges <ligges at statistik.uni-dortmund.de>
> � : Albert Picado <albert_picado at yahoo.fr>
> Cc : r-help at stat.math.ethz.ch
> Envoy� le : Samedi, 12 Ao�t 2006, 3h57mn 16s
> Objet : Re: [R] adding columns to a table after a
> loop
> 
> 
> Albert Picado wrote:
> > Dear list,
> > 
> > I am trying to find the way to add columns to a
> table
> > (or a matrix) after a loop. The result of this
> loop is
> > an array and I would like to get all the results
> in a
> > single table once the loop is finish. I have
> > reproduced a simplified example below:
> > 
> >> a<- 1
> >> b <- matrix()
> >> while (a <= 4) {
> > + b<-rnorm(10)
> > + a<- a +1
> > + }
> 
> 
> Staying in your example:
> 
> a <- 1
> b <- matrix(nrow=10, ncol=4)
> while(a <= 4){
>      b[,i] <- rnorm(10)
>      a <- a + 1
> }
> 
> Uwe Ligges

There is a minor typo in the above  example. b[,1]
should read b[,a].  It works very nicely with that
small correction.



More information about the R-help mailing list