Dear all,
I want to
write ck<-cbind(rep(pk[1,1],4),rep(pk[1,2],4),rep(pk[1,3],4)) state ment
in a loop . How can I write it ?
> pk
[,1] [,2] [,3]
[1,] -1.1354816 0.9808877 -0.9446314
[2,] 0.7787378 0.4536944 0.3204882
[3,] -1.7274907 1.5112011 1.4481839
[4,] 1.0629145 0.5976109 -0.5277638
> pk<-matrix(rnorm(12),nrow=4,ncol=3)
> pk
[,1] [,2] [,3]
[1,] -1.1354816 0.9808877 -0.9446314
[2,] 0.7787378 0.4536944 0.3204882
[3,] -1.7274907 1.5112011 1.4481839
[4,] 1.0629145 0.5976109 -0.5277638
> ck<-cbind(rep(pk[1,1],4),rep(pk[1,2],4),rep(pk[1,3],4))
> ck
[,1] [,2] [,3]
[1,] -1.135482 0.9808877 -0.9446314
[2,] -1.135482 0.9808877 -0.9446314
[3,] -1.135482 0.9808877 -0.9446314
[4,] -1.135482 0.9808877 -0.9446314
Thanks for your help
Fernanda Lopez
Netherlands
[[alternative HTML version deleted]]
try this:
pk <- matrix(rnorm(12), 4, 3)
matrix(rep(pk[1, ], each = 4), 4)
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "fernanda lopez" <lopezfer123 at gmail.com>
To: <R-help at stat.math.ethz.ch>
Sent: Monday, July 14, 2008 10:33 AM
Subject: [R] Loop problem
> Dear all,
> I want to
> write ck<-cbind(rep(pk[1,1],4),rep(pk[1,2],4),rep(pk[1,3],4))
> state ment
> in a loop . How can I write it ?
>
>
>
>
>
>> pk
> [,1] [,2] [,3]
> [1,] -1.1354816 0.9808877 -0.9446314
> [2,] 0.7787378 0.4536944 0.3204882
> [3,] -1.7274907 1.5112011 1.4481839
> [4,] 1.0629145 0.5976109 -0.5277638
>
>
>
>> pk<-matrix(rnorm(12),nrow=4,ncol=3)
>> pk
> [,1] [,2] [,3]
> [1,] -1.1354816 0.9808877 -0.9446314
> [2,] 0.7787378 0.4536944 0.3204882
> [3,] -1.7274907 1.5112011 1.4481839
> [4,] 1.0629145 0.5976109 -0.5277638
>
>> ck<-cbind(rep(pk[1,1],4),rep(pk[1,2],4),rep(pk[1,3],4))
>> ck
> [,1] [,2] [,3]
> [1,] -1.135482 0.9808877 -0.9446314
> [2,] -1.135482 0.9808877 -0.9446314
> [3,] -1.135482 0.9808877 -0.9446314
> [4,] -1.135482 0.9808877 -0.9446314
>
>
> Thanks for your help
>
> Fernanda Lopez
> Netherlands
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Hi, do you mean this? pk<-matrix(rnorm(12),nrow=4,ncol=3) ck1<-cbind(rep(pk[,1],4),rep(pk[,2],4),rep(pk[,3],4)) ## or ck2<-cbind(rep(pk[,1],each=4),rep(pk[,2],each=4),rep(pk[,3],each=4)) pk ck1 ck2 best, Daniel fernanda lopez wrote:> > Dear all, > I want to > write ck<-cbind(rep(pk[1,1],4),rep(pk[1,2],4),rep(pk[1,3],4)) state > ment > in a loop . How can I write it ? > > > > > >> pk > [,1] [,2] [,3] > [1,] -1.1354816 0.9808877 -0.9446314 > [2,] 0.7787378 0.4536944 0.3204882 > [3,] -1.7274907 1.5112011 1.4481839 > [4,] 1.0629145 0.5976109 -0.5277638 > > > >> pk<-matrix(rnorm(12),nrow=4,ncol=3) >> pk > [,1] [,2] [,3] > [1,] -1.1354816 0.9808877 -0.9446314 > [2,] 0.7787378 0.4536944 0.3204882 > [3,] -1.7274907 1.5112011 1.4481839 > [4,] 1.0629145 0.5976109 -0.5277638 > >> ck<-cbind(rep(pk[1,1],4),rep(pk[1,2],4),rep(pk[1,3],4)) >> ck > [,1] [,2] [,3] > [1,] -1.135482 0.9808877 -0.9446314 > [2,] -1.135482 0.9808877 -0.9446314 > [3,] -1.135482 0.9808877 -0.9446314 > [4,] -1.135482 0.9808877 -0.9446314 > > > Thanks for your help > > Fernanda Lopez > Netherlands > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. > >-- View this message in context: http://www.nabble.com/Loop-problem-tp18439649p18439918.html Sent from the R help mailing list archive at Nabble.com.
Try this: pk[rep(1, 4), ] On Mon, Jul 14, 2008 at 4:33 AM, fernanda lopez <lopezfer123 at gmail.com> wrote:> Dear all, > I want to > write ck<-cbind(rep(pk[1,1],4),rep(pk[1,2],4),rep(pk[1,3],4)) state ment > in a loop . How can I write it ? > > > > > >> pk > [,1] [,2] [,3] > [1,] -1.1354816 0.9808877 -0.9446314 > [2,] 0.7787378 0.4536944 0.3204882 > [3,] -1.7274907 1.5112011 1.4481839 > [4,] 1.0629145 0.5976109 -0.5277638 > > > >> pk<-matrix(rnorm(12),nrow=4,ncol=3) >> pk > [,1] [,2] [,3] > [1,] -1.1354816 0.9808877 -0.9446314 > [2,] 0.7787378 0.4536944 0.3204882 > [3,] -1.7274907 1.5112011 1.4481839 > [4,] 1.0629145 0.5976109 -0.5277638 > >> ck<-cbind(rep(pk[1,1],4),rep(pk[1,2],4),rep(pk[1,3],4)) >> ck > [,1] [,2] [,3] > [1,] -1.135482 0.9808877 -0.9446314 > [2,] -1.135482 0.9808877 -0.9446314 > [3,] -1.135482 0.9808877 -0.9446314 > [4,] -1.135482 0.9808877 -0.9446314 > > > Thanks for your help > > Fernanda Lopez > Netherlands > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >