How to remove rows with any zero value

前端 未结 8 681
时光取名叫无心
时光取名叫无心 2020-11-28 07:04

I have a problem to solve how to remove rows with a Zero value in R. In others hand, I can use na.omit() to delete all the NA values or use complete.cases

8条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 07:47

    There are a few different ways of doing this. I prefer using apply, since it's easily extendable:

    ##Generate some data
    dd = data.frame(a = 1:4, b= 1:0, c=0:3)
    
    ##Go through each row and determine if a value is zero
    row_sub = apply(dd, 1, function(row) all(row !=0 ))
    ##Subset as usual
    dd[row_sub,]
    

提交回复
热议问题