Reputation: 910
I have a data.frame, here an example:
df <- data.frame(object = c("apples","tomatoes", "apples","pears" ),
Value = c(50,10,30,40))
I make a copy of this df to keep it in format data.frame:
forDT <- df
And the new copied data.frame I assigned to data.table performing a split of the data:
require(data.table)
tmp = setDT(forDT)[, list(grp=list(.SD)), by=.(object), .SDcols=names(forDT)]
setattr(import_split <- tmp$grp, 'names', paste(tmp$object, sep="."))
In the following step I need the original data.frame which I didn't convert into data.table for further calculations (as I am more familiar with data.frames, thats why I made the copy in the beginning). However, the original df
is also of data.table format. What I'm doing wrong? Ideas? Thanks
Upvotes: 0
Views: 82
Reputation: 193637
The set*
functions in "data.table" do not make copies of your data.
To make a copy, you should use as.data.table
or use the copy
function from the "data.table" package.
Upvotes: 3