How should I drop blocks of NAs from an R data.table

后端 未结 2 1007
-上瘾入骨i
-上瘾入骨i 2021-02-05 19:37

I have a large R data.table with a multi column key, where some value columns contain some NA. I\'d like to remove groups that are entirely NA in one or more value

2条回答
  •  花落未央
    2021-02-05 20:25

    What about using complete.cases function ?

    DT[complete.cases(DT),]
    

    It will drop the rows that have a column value with NA

    > DT[complete.cases(DT),]
        Series Id Value1 Value2
     1:      b  4      4      1
     2:      b  5      5      2
     3:      b  6      6      3
     4:      c  7      7      4
     5:      c  8      8      5
     6:      c  9      9      6
     7:      f  4      4      1
     8:      f  5      5      2
     9:      f  6      6      3
    10:      g  7      7      4
    11:      g  8      8      5
    12:      g  9      9      6
    13:      j  4      4      1
    14:      j  5      5      2
    15:      j  6      6      3
    16:      k  7      7      4
    17:      k  8      8      5
    18:      k  9      9      6
    

提交回复
热议问题