R/sort-by.R
sort_by.Rd
Sort an object by another object
sort_by(x, by, ...)
A vector
Another vector
Additional arguments passed to base::order()
base::order()
The values of x, resorted
x
l3 <- letters[1:3] sort_by(l3, c(3, 2, 1)) #> [1] "c" "b" "a" # make a factor object with the reversed order f <- factor(l3, levels = rev(l3)) sort_by(f, l3) #> [1] a b c #> Levels: c b a sort_by(1:3, rev(l3)) #> [1] 3 2 1