Hi Alexandra,

Here is an alternative without using a loop:

matrix(sapply(a, rep, T), ncol = 1)

HTH,
Jorge


On Wed, Aug 24, 2011 at 9:10 PM, Soberon Velez, Alexandra Pilar <> wrote:

> Hello,
>
> I want to create a matrix of N random numbers with a uniform distributions.
> Later, I want to repeat T times each row of this matrix. For this I do the
> following loop:
>
> N<-45
> T<-10
> n<-N*T
> a<-matrix(runif(N,min=-1,max=1),nr=N)
>
> mymat<-matrix(rep(NA,n),nr=n,nc=1)
> for(i in i:N){
> b<-rep(a[i,],T)
> mymat[i,]<-b
> }
>
> Mi problem is that with this loop I can see the output of the loop but I
> canot get the matrix (mymat) that contains the full output of the loop.
>
> Please, somebody know how can I create a matrix that contains the output of
> the loop with a dimension NTx1 (450x1).
>
> Thanks a lot for your help.
> Alexandra
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to