[R] repeating a dataframe n times in the direction of the rows
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Mon Nov 11 12:30:38 CET 2002
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list