Changing factor levels on a column with setattr is sensitive for how the column was created

后端 未结 1 793
花落未央
花落未央 2021-01-12 10:51

I want to change factor levels of a column using setattr. However, when the column is selected the standard data.table way (dt[ , col]

相关标签:
1条回答
  • 2021-01-12 11:37

    It might help to understand if you look at the address from both expressions:

    address(d$x)
    # [1] "0x10e4ac4d8"
    address(d$x)
    # [1] "0x10e4ac4d8"
    
    
    address(d[,x])
    # [1] "0x105e0b520"
    address(d[,x])
    # [1] "0x105e0a600"
    

    Note that the address from the first expression doesn't change when you call it multiple times, while the second expression does which indicates it is making a copy of the column due to the dynamic nature of the address, so setattr on it will have no effect on the original data.table.

    0 讨论(0)
提交回复
热议问题