0

So I have a data frame.

In which some specific variables may have the value of 0. But I want to delete the row only if the value of zero shows up on 3 or 4 of these specific variables.

Thank you

Alex Rika
  • 25
  • 5

1 Answers1

0

It can be done with filter_at by specifying the columns of interest

library(dplyr)
df1 %>% 
   filter_at(vars(col1, col2), all_vars(. != 0))

data

df1 <- data.frame(col1 = c(0, 1, 2, 3), col2 = c(1, 0, 2, 4), col3 = c(1, 1, 0, 0))
akrun
  • 874,273
  • 37
  • 540
  • 662
  • So I have these variables: login_count : whitch is integer text_length: might be 1 to thousands assignment: 1 to hundreds meaning he had an assignment mindmap_length: also 1 to thousands ( Letter counting) activity: also integer 1 to hunders So basicaly a user to have values >0 on these values the value login must be at least 1 meaning he loged in to the system and wrote something Then also Assignment has to have a value meaning the assignment he had to do But login and assignment might be 1 and the others might be 0 and I still need to delete the row. So how i do if else here? – Alex Rika Mar 06 '19 at 14:58
  • @AlexRika I showed a reproducible example based on your description. Sorry, it is not clear to me without a reproducible example – akrun Mar 06 '19 at 15:00
  • Edited it please check – Alex Rika Mar 06 '19 at 15:02
  • @AlexRika Please edit your post with a small example and your expected output. – akrun Mar 06 '19 at 15:03