[R] How to duplicate rows in dataframe?
mike_saunders at umenfa.maine.edu
Mon Dec 13 21:37:28 CET 2004
You should be able to do this with the command:
See order or sort in the R help for optional arguments that can customize
the way you want to deal with ties.
----- Original Message -----
From: "cstrato" <cstrato at aon.at>
To: <r-help at stat.math.ethz.ch>
Sent: Monday, December 13, 2004 2:02 PM
Subject: [R] How to duplicate rows in dataframe?
> Dear all:
> I have the following (simple?) problem:
> Consider a dataframe where the first column contains
> integers used as index, e.g.
> Now I have the following vector used to sort the dataframe:
> x <- c(13,24,32,46)
> Sorting the dataframe can be done by using order.
> However consider the following vector:
> x <- c(13,32,13,24,46,24,24)
> Now I want to get the dataframe in the order of the rows
> defined in x, i.e. the dataframe contains duplicate rows.
> One way to achieve this would be to use rbind in a for-loop.
> My question is:
> Is there an easier and - more important - faster way to
> obtain the dataframe as defined in x?
> Thank you in advance.
> Best regards
> C.h.i.s.t.i.a.n S.t.r.a.t.o.w.a
> V.i.e.n.n.a A.u.s.t.r.i.a
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide!
More information about the R-help