Joshua G. answered 10/15/24
PhD in Biostatistics with 11 Years of R Programming Experience
Yes, there is. After running your provided code for loading the "data.table" library, creating the x variable, and creating the neworder variable, you can reorder the columns of x without copying the entire dataset again with the following code statement:
setcolorder(x,neworder)
The preceding code statement reorders the columns of x by reference, which means that the entire dataset was not copied again as desired. The following website link provides the documentation for the R function "setcolorder":
https://www.rdocumentation.org/packages/data.table/versions/1.15.4/topics/setcolorder