You can remove row names and convert them to a column by reference (without reallocating memory with -> ) using setDT and its keep.rownames = TRUE argument from the data.table package
library(data.table) setDT(df, keep.rownames = TRUE)[]
As @snoram mentioned, you can give the new column any name you want, for example, setDT(df, keep.rownames = "newname") will add "newname" as the row column.
David Arenburg Apr 08 '15 at 9:53 on 2015-04-08 09:53
source share