I want to reorder the rows of a data.table according to some given sequence of indices, which is what setcolorder does for columns. Is there a function for this?
Here is a reproducible example, with the expected output.
> DT = data.table(mtcars, keep.rownames=TRUE)[1:3]
> DT
rn mpg cyl disp hp drat wt qsec vs am gear carb
1: Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
2: Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
3: Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
> ord = c(3,1,2)
> setroworder(DT, ord)
> DT
rn mpg cyl disp hp drat wt qsec vs am gear carb
1: Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
2: Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
3: Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4