Hallo, I'll need a matrix with n rows of the an identical vector.> h[1] 3 3 3 3 2 2 2 The nmatrix should look like this:> x<-rbind(h,h,h) > x[,1] [,2] [,3] [,4] [,5] [,6] [,7] h 3 3 3 3 2 2 2 h 3 3 3 3 2 2 2 h 3 3 3 3 2 2 2 but I need n rows which must be variable. Can anyone help me? thanks Andreas [[alternative HTML version deleted]]
Friedrich, Andreas (dit) wrote:> Hallo, > > I'll need a matrix with n rows of the an identical vector. > > > > >>h > > [1] 3 3 3 3 2 2 2 > > > The nmatrix should look like this: > > >>x<-rbind(h,h,h) >>x > > [,1] [,2] [,3] [,4] [,5] [,6] [,7] > h 3 3 3 3 2 2 2 > h 3 3 3 3 2 2 2 > h 3 3 3 3 2 2 2 > > > > but I need n rows which must be variable. Can anyone help me?x <- matrix(h, nrow = n, ncol = length(h), byrow = TRUE) Uwe Ligges> thanks Andreas > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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
try this: h <- rep(3:2, c(4, 3)) ############ n <- 10 matrix(rep(h, n), nrow = n, byrow = TRUE) Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Friedrich, Andreas (dit)" <Andreas.Friedrich at dit.de> To: <r-help at stat.math.ethz.ch> Sent: Thursday, June 02, 2005 2:16 PM Subject: [R] repeated vector in matrix> Hallo, > > I'll need a matrix with n rows of the an identical vector. > > > >> h > [1] 3 3 3 3 2 2 2 > > > The nmatrix should look like this: > >> x<-rbind(h,h,h) >> x > [,1] [,2] [,3] [,4] [,5] [,6] [,7] > h 3 3 3 3 2 2 2 > h 3 3 3 3 2 2 2 > h 3 3 3 3 2 2 2 > > > > but I need n rows which must be variable. Can anyone help me? > > thanks Andreas > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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 >
"Friedrich, Andreas (dit)" <Andreas.Friedrich at dit.de> writes:> Hallo, > > I'll need a matrix with n rows of the an identical vector. > > > > > h > [1] 3 3 3 3 2 2 2 > > > The nmatrix should look like this: > > > x<-rbind(h,h,h) > > x > [,1] [,2] [,3] [,4] [,5] [,6] [,7] > h 3 3 3 3 2 2 2 > h 3 3 3 3 2 2 2 > h 3 3 3 3 2 2 2 > > > > but I need n rows which must be variable. Can anyone help me?Like this, for instance:> h<-c(3, 3, 3, 3, 2, 2, 2) > n<-5 > matrix(h, nrow=n, ncol=length(h), byrow=TRUE)[,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 3 3 3 3 2 2 2 [2,] 3 3 3 3 2 2 2 [3,] 3 3 3 3 2 2 2 [4,] 3 3 3 3 2 2 2 [5,] 3 3 3 3 2 2 2 -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
On Jun 2, 2005, at 01:23 pm, Dimitris Rizopoulos wrote:> try this:> h <- rep(3:2, c(4, 3)) > ############ > n <- 10 > matrix(rep(h, n), nrow = n, byrow = TRUE) >Hi outer() also works: > h <-rep(c(3,2),c(4,3)) > outer(rep(1,8),h) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 3 3 3 3 2 2 2 [2,] 3 3 3 3 2 2 2 [3,] 3 3 3 3 2 2 2 [4,] 3 3 3 3 2 2 2 [5,] 3 3 3 3 2 2 2 [6,] 3 3 3 3 2 2 2 [7,] 3 3 3 3 2 2 2 [8,] 3 3 3 3 2 2 2 > -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743