[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
Hi,
if I got it right I'd suggest to use match (which would allow you to use
also character vectors)
So
tdf[match(tv,tdf[,1]),]
will give you tdf in the same order as tv
HIH
Ste
On Mon, Jan 23, 2006 at 04:09:58PM +0000, Ken Termiso wrote:
<Ken>Let me clarify the problem a bit further:
<Ken>
<Ken>tv <- 1:11108
<Ken>
<Ken>tdf <- data.frame(cbind(11108:1, 22216:11109))
<Ken>
<Ken>
<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>
<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>
<Ken>Thanks,
<Ken>ken
<Ken>
<Ken>______________________________________________
<Ken>R-help at stat.math.ethz.ch mailing list
<Ken>https://stat.ethz.ch/mailman/listinfo/r-help
<Ken>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list