data.table := assignments when variable has same name as a column

后端 未结 1 552
北恋
北恋 2020-12-07 02:09

I found this strange behavior when assigning a value to a position. If the variable has the same name as a column it thinks we are talking about the column:

         


        
相关标签:
1条回答
  • 2020-12-07 02:45

    You can always use get, which allows you to specify the environment:

    dt1[1, a := get("a", envir = .GlobalEnv)]
    #    a
    #1: 18
    

    Or just:

    a <- 42
    dt1[1, a := .GlobalEnv$a]
    #    a
    #1: 42
    
    0 讨论(0)
提交回复
热议问题