NA in data.table

前端 未结 3 1642
遇见更好的自我
遇见更好的自我 2021-02-20 15:24

I have a data.table that contains some groups. I operate on each group and some groups return numbers, others return NA. For some reason data.ta

3条回答
  •  礼貌的吻别
    2021-02-20 15:45

    you can also do something like this :

    dtb <- data.table(a=1:10)
    
    mat <- ifelse(dtb == 9,NA,dtb$a)
    

    The above command will give you matrix but you can change it back to data.table

    new.dtb <- data.table(mat)
    new.dtb
         a
     1:   1
     2:   2
     3:   3
     4:   4
     5:   5
     6:   6
     7:   7
     8:   8
     9:  NA
    10:  10
    

    Hope this helps.

提交回复
热议问题