5

I have this dataframe with a set of zero values along two columns. df

 Sl_No  No_of_Mails No_of_Responses
 1       10           2
 2        0           0
 3       20           0
 4       10          10
 5        0           0
 6        0          NA
 7       10          NA
 8       10           0

I want to remove those rows where No_of_Mails equals zero without disturbing the other column. I have tried the following code

row_sub = apply(df, 1, function(row) all(row !=0 ))
df[row_sub,]

This removes all the 0 values including the one from the number_of_responses column. I wish to have that column undisturbed I have also tried this

 df[df$No_of_Mails][!(apply(df, 1, function(y) any(y == 0))),].

This deletes all the rows and gives me a table with zero rows.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Raghavan vmvs
  • 1,213
  • 1
  • 10
  • 29

1 Answers1

14

Just subset the data frame based on the value in the No_of_Mails column:

df[df$No_of_Mails != 0, ]

Demo

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360