R: Sort multiple columns by another data.frame?

Viewed 18636

I'm trying to make sense of how to sort one data.frame based on multiple columns in another. This question does this with vectors. Can someone suggest a way to do the equivalent with data.frames?

Here's some sample data.

x1 <- data.frame(a=1:5, b=letters[1:5], c=rnorm(5))
x2 <- data.frame(a=c(4,4,2), b=c("d", "d", "b"), d=rnorm(3))

So I want to sort x2 by the first two columns of x1. My actual data is much more complicated, but this replicates the idea...

3 Answers
Related