I'm trying to do some transformation on the variable TP_STATUS_REDACAO from the dataset called DFtest2. In order to preserve the original data, I have made a copy called DFtest.means.
Working on the Rnotebook, I've ran the following commands:
I've expected that only the column DFtest.means$TP_STATUS_REDACAO would have been changed, however the column DFtest2$TP_STATUS_REDACAO has also became NA.
I have no clue about what's going on and I couldn't find an answer on the internet.
I'm a bit confused by the above code because I'm not sure what := means. Do you mean '!=' or maybe '<-'. If the latter, this could cause 'DFtest2$TP_STATUS_REACA0' to become NA, especially if 'DFtest2' was attached.
Also, I always use 'is.na()' when testing for NAs, as 'X != NA' returns NA.
# add/update/delete by reference (see ?assign)
print(DT[, z:=42L]) # add new column by reference
print(DT[, z:=NULL]) # remove column by reference
print(DT["a", v:=42L, on="x"]) # subassign to column
print(DT["b", v2:=84L, on="x"]) # subassign to new column (NA padded)
DT[, m:=mean(v), by=x][] # add new column by reference by group