[R] ordering a data frame to same order as a chr vector

Stefano Calza stecalza at tiscali.it
Mon Jan 23 17:24:12 CET 2006


if I got it right I'd suggest to use match (which would allow you to use 
also character vectors)



will give you tdf in the same order as tv


On Mon, Jan 23, 2006 at 04:09:58PM +0000, Ken Termiso wrote:
<Ken>Let me clarify the problem a bit further:
<Ken>tv <- 1:11108
<Ken>tdf <- data.frame(cbind(11108:1, 22216:11109))
<Ken>In this example, what I would like to do is re-order the entire tdf data 
<Ken>frame based on its first column (since the contents of tdf[,1] are identical 
<Ken>to tv, just not necessarily in the same order in my problem, but here 
<Ken>obviously the tdf data frame is already ordered the same as tv).
<Ken>I would like to use the vector tv to give tdf the same exact order as tv, 
<Ken>based on that first column of tdf which is identical to tv.
<Ken>R-help at stat.math.ethz.ch mailing list
<Ken>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

More information about the R-help mailing list