Search code examples
rdataframedplyrfilterdelete-row

Discard value=1 across entire row


Rows where all the values are 1. I wish to remove all such rows.


Solution

  • As these are 1s and 0s, an option is also with pmin

    df[!do.call(pmin, df),]
     V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
    2  0  0  0  0  0  0  0  0  0   0
    3  0  0  0  0  0  0  0  0  0   0
    4  0  0  0  0  0  0  0  0  0   0
    5  0  0  0  0  0  0  0  0  0   0
    7  0  0  0  0  0  0  0  0  0   0
    8  0  0  0  0  0  0  0  0  0   0
    

    Or using all with apply (less efficient)

    df[!apply(df, 1, all),]
      V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
    2  0  0  0  0  0  0  0  0  0   0
    3  0  0  0  0  0  0  0  0  0   0
    4  0  0  0  0  0  0  0  0  0   0
    5  0  0  0  0  0  0  0  0  0   0
    7  0  0  0  0  0  0  0  0  0   0
    8  0  0  0  0  0  0  0  0  0   0