[R] How to rep a matrix by row?

Gabor Grothendieck ggrothendieck at gmail.com
Sat Apr 29 19:28:27 CEST 2006


Try this where DF is your data frame:

DF[rep(seq(nrow(DF)), each = 3), ]

On 4/29/06, Jiantao Shi <bioconductor.cn at gmail.com> wrote:
> Hi,
> i have a dataframe like this,
>
> Source    Treat    Drug    Replicate
> > control    0    A    1
> > control    10    A    2
> > control    30    A    3
> > 1    0    A    1
>
>
> And i want to rep this  dataframe  3 times by row,the resulting  matrix  as
> follow,
>
> Source    Treat    Drug    Replicate
> > control    0    A    1
> > control    0    A    1
> > control    0    A    1
> > control    10    A    2
> > control    10    A    2
> > control    10    A    2
> > control    30    A    3
> > control    30    A    3
> > control    30    A    3
> > 1    0    A    1
> > 1    0    A    1
> > 1    0    A    1
>
>
> So is there a easy way to do ?
> thanks.
>
> Jianao Shi
>
>        [[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
>




More information about the R-help mailing list