Fuv8
Fuv8

Reputation: 905

Subset rows containing not 0 elements in a data.frame

I have a data.frame that looks like this:

  cln1    cln2    cln3    cln4    
    0      1        2      0   
    3      9        7     12
    1      0       13      0   
    4     98       23     11    

I would like to subset only that rows and columns not containing 0 elements. The desired output will be:

  cln1    cln2    cln3    cln4    
    3      9        7     12
    4     98       23     11    

Upvotes: 1

Views: 1123

Answers (1)

A5C1D2H2I1M1N2O1R2T1
A5C1D2H2I1M1N2O1R2T1

Reputation: 193687

Assuming your data.frame is called "mydf":

> mydf[!rowSums(mydf == 0), ]
  cln1 cln2 cln3 cln4
2    3    9    7   12
4    4   98   23   11

Upvotes: 4

Related Questions