Count number of zeros per row, and remove rows with more than n zeros

后端 未结 1 1607
抹茶落季
抹茶落季 2020-11-27 17:30

I have a question about counting zeros per row. I have a dataframe like this:

a = c(1,2,3,4,5,6,0,2,5)
b = c(0,0,0,2,6,7,0,0,0)
c = c(0,5,2,7,3,1,0,3,0)
d =          


        
相关标签:
1条回答
  • 2020-11-27 18:14

    It's not only possible, but very easy:

    DF[rowSums(DF == 0) <= 4, ]
    

    You could also use apply:

    DF[apply(DF == 0, 1, sum) <= 4, ]
    
    0 讨论(0)
提交回复
热议问题