Sort vector of integers in specific (custom) order
A somewhat convoluted option:
x[order(factor(x,levels = c(2,1,3)))]
or obviously, just the order
call for just the indices.
A simple remapping of the values works:
x <- sample(1:3, 10, replace=T)
x
[1] 2 3 1 1 3 2 2 3 3 2
order(c(2,1,3)[x])
[1] 1 6 7 10 3 4 2 5 8 9