[R] ordering a data frame to same order as a chr vector
Dimitris Rizopoulos
dimitris.rizopoulos at med.kuleuven.be
Mon Jan 23 17:13:57 CET 2006
probably you are looking for something like the following:
dat <- data.frame(chr = letters[1:20], x = rnorm(20), y = rnorm(20))
chr.vec <- sample(letters[1:20])
####################3
dat[match(chr.vec, dat$chr), ]
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Ken Termiso" <jerk_alert at hotmail.com>
To: <r-help at stat.math.ethz.ch>
Sent: Monday, January 23, 2006 4:55 PM
Subject: [R] ordering a data frame to same order as a chr vector
> Hi all,
>
> I've got a data frame that has an identical column to a chr vector.
> I would
> like to use the chr vector to order the rows of the data frame to be
> identical to the order in the chr vector (the contents of the chr
> vector are
> completely identical to one col of the data frame), but this is
> proving
> trickier than it sounds..
>
> Any help would be much obliged,
> -Ken
>
> ______________________________________________
> 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
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
More information about the R-help
mailing list