set.seed(45L)
DT = data.table(A=sample(3, 10, TRUE),
B=sample(letters[1:3], 10, TRUE), C=sample(10))
setcolorder(DT, c("C", "A", "B"))
#incomplete specification
setcolorder(DT, "A")
# insert new column as first column
set(DT, j="D", value=sample(10))
setcolorder(DT, "D", before=1)
# move column to last column place
setcolorder(DT, "A", after=ncol(DT))
Run the code above in your browser using DataLab