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

From: John Kane <jrkrideau_at_yahoo.ca>
Date: Sun 13 Aug 2006 - 03:30:33 EST

Albert

> Dear Uwe,
>
> Thanks for your answer.

----clip

> De : Uwe Ligges <ligges@statistik.uni-dortmund.de>
> � : Albert Picado <albert_picado@yahoo.fr>
> Cc : r-help@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.



R-help@stat.math.ethz.ch 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. Received on Sun Aug 13 03:34:42 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 13 Aug 2006 - 06:20:51 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.