Removing rows of common values if one rows meets a condition

Viewed 42

My dataframe consists of number of answers to questions grouped by answer-type, question, school.

I am trying to formulate a filter which will remove alle rows with common values (School, Question, Segment) if a row meets the condition (not enough answers).

Answers < "Required n answers" -> Delete rows which contain same Segment, Question and School.

Reasoning is that, all answers must be removed if one answer doesn't meet the requirement, but I have multiple segments, questions and schools.

I hope this is not too confusing, I know I explain poorly, but thanks a lot!

Constructed example

1 Answers

Using dplyr :

library(dplyr)
df %>% 
    group_by(Segment, Question, School) %>%
    filter(all(Answers > `Required n answers`))
Related