I just stumbled upon some weird behavior in data.table. In short, using ": =" to change (replace) a column value in a data table. The table also changes the values in another data table (which is a copy of the original data table before the operation: =). Sample code below.
Am I missing something fundamental in a great package, or if there is an error report?
Subquery: Iselse () is the best way to change the values as shown below (in a fairly large table, ~ 10 m rows)? It does the job as expected, fast enough (a few seconds), but with verbose = TRUE data.table complains ("The RHS for element 1. was duplicated. Either a NAMED vector or a reworked RHS list.), And I could not decrypt post so far :)
library(data.table)
options(datatable.verbose=TRUE)
DT1 <- data.table(f=as.integer(c(1,2,1,1,1,2,1)))
DT2 <- DT1
tables()
DT1
DT2
identical(DT1, DT2)
DT1[, f := as.character(ifelse(f==1,"a","b"))]
tables()
DT1
DT2
identical(DT1, DT2)
, :
R version 2.15.3 (2013-03-01) -- "Security Blanket"
Platform: x86_64-w64-mingw32/x64 (64-bit)
data.table 1.8.8
All 943 tests in test.data.table() completed ok in 27.869sec
.