Skip to content
Prev 219698 / 398500 Next

ordering data frame

phoebe kong wrote:
Are these really data.frames? They looks like matrices. You do not 
provide ?dput output.
My example uses data.frames.  ?match and ?order are the important functions.

df1 <- data.frame(a = sample(LETTERS[1:5]), b = rnorm(5))
df2 <- data.frame(a = sample(LETTERS[1:5]), b = rnorm(5))

df1[order(match(df1$a, df2$a)), ]