Wolfram Fischer
2002-Nov-11 10:32 UTC
[R] repeating a dataframe n times in the direction of the rows
Question: How can a repeat a dataframe n times in the direction of the rows? (Or: How I can rbind a dataframe n times ?) Example Data: x <- data.frame( alpha=letters[1:3], num=1:3 ) n <- 4 Complicated solution: To rbind a dataframe n times I can program a loop: xr <- x for( i in 2:n ) xr <- rbind( xr, n ) Observation: To cbind a dataframe n times I can use rep: xc <- data.frame( rep( x, n ) ) Is there a similar possibility to repeat in the direction of the rows? Wolfram -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
2002-Nov-11 11:30 UTC
[R] repeating a dataframe n times in the direction of the rows
Wolfram Fischer <wolfram at fischer-zim.ch> writes:> Question: > How can a repeat a dataframe n times > in the direction of the rows? > (Or: How I can rbind a dataframe n times ?) > > > Example Data: > x <- data.frame( alpha=letters[1:3], num=1:3 ) > n <- 4 > > > Complicated solution: To rbind a dataframe n times I can program a loop: > > xr <- x > for( i in 2:n ) xr <- rbind( xr, n ) > > > Observation: To cbind a dataframe n times I can use rep: > > xc <- data.frame( rep( x, n ) ) > > > Is there a similar possibility to repeat in the direction of the rows?How about x[rep(1:nrow(x),n),] ? -- 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 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
AlessandroSemeria@cramont.it
2002-Nov-11 11:51 UTC
[R] repeating a dataframe n times in the direction of the rows
You can use 't' to transpose your data.frame then you do what you said by 'cbind' and at last you transpose again. Best! A.S. ---------------------------------- Sincerely yours. Dr. Alessandro Semeria Tel. +39 544 536811 Models and Simulation Lab of Fax. +39 544 538663 The Environment Research Center - Montecatini (Edison Group), E-mail: asemeria at cramont.it Via Ciro Menotti 48, 48023 Marina di Ravenna (RA), Italy -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._