Fastest way to drop rows with missing values?

前端 未结 4 461
小鲜肉
小鲜肉 2021-01-02 20:23

I\'m working with a large dataset x. I want to drop rows of x that are missing in one or more columns in a set of columns of x, that

4条回答
  •  长发绾君心
    2021-01-02 21:17

    This should be faster than using apply:

    x[rowSums(is.na(x[, ..varcols])) == 0, ]
    #    var1 var2 textcol
    # 1:    0    0       e
    # 2:    0    1       f
    # 3:    1    0       h
    # 4:    1    1       i
    

提交回复
热议问题