A niggling problem. Simple example. Suppose I have the following:
df <- data.frame(x = as.factor(1:10),
y = rnorm(10, 0, 1))
x_order = c("3", "1", "5", "7", "8", "9", "2", "6", "10", "4")
I would like to reorder the rows of df
such that the values in df$x
appear in the order specified in the x_order
vector. Is there an easy way to do this please?
Thank you.