Remove rows with Inf and NaN in R

后端 未结 1 1457
轻奢々
轻奢々 2021-02-15 04:05

I have the following data:

> dat
               ID     Gene   Value1   Value2
1      NM_013468   Ankrd1       Inf      Inf
2      NM_023785     Ppbp       Inf         


        
相关标签:
1条回答
  • 2021-02-15 04:47

    You can't check for NaN with the normal compare operators. You can do so for Inf, but you would also have to check for the negative case. Better to use one of those functions: https://stat.ethz.ch/R-manual/R-devel/library/base/html/is.finite.html

    Edit: tonytonov pointed out, that is.finite(NaN) is FALSE, which makes it sufficient to use in this case. You therefore just need

    dat[is.finite(dat$Value1) & is.finite(dat$Value2), ]
    
    0 讨论(0)
提交回复
热议问题