I want to change column factor levels using setattr . However, when a column is selected in the standard way data.table ( dt[ , col] ), levels not updated. On the other hand, when you select a column in an unorthodox way in the data.table setting, namely when using $ -it it works.
library(data.table)
It looks like I missed some basics of data.table ( R ?). Can someone explain what is happening?
I found two more posts on setattr and levels :
setattr on levels saving unwanted duplicates (R data.table)
How to change factor column levels in a data table.
Both of them used $ to select a column. None of them mentioned the method [ , col] .
r data.table
Henrik
source share