New user to R...basic allude me...filter multiple objects with conditions in one line of code

I am new to R (and am really learning coding for the first time). I am trying to filter out responses to 4 objects that do not meet a certain criteria. I was able to do one object, but not sure how to add all four to the code. These are attention check items. I need to drop these out for any and all who did not meet this conditions.

This is my line of code
HW3P<- filter(Homework_3_dataset,Homework_3_dataset$Att1==2)

I need to add the same for Att2==2, Att3==1, and Att4==7.

Again, I am new so not only is the code new, the language is new.

I appreciate the help

You can simply add | at the end of every condition. Hope that helps.

HW3P <- filter(Homework_3_dataset, Homework_3_dataset$Att1==2 | Homework_3_dataset$Att2==2 | Homework_3_dataset$Att3==1 | Homework_3_dataset$Att4==7)

Welcome. This should work. Less typing too.

library(dplyr)
HW3P <- Homework_3_dataset %>% 
  filter(Att1 == 2,
         Att2 == 2,
         Att3 == 1,
         Att4 == 7)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.