This is my df = myproject
myproject <- data.frame(
Participant = 1:5,
`futuremw:1` = c(1L, 2L, 1L, 1L, NA),
`pastmw:1` = c(1L, 1L, 2L, 1L, NA),
`proportionfuturepast:1` = c(4L, 7L, 1L, 2L, NA),
my_video_item_duration_min = c(5, 1, 7.02, 6, 6),
check.names = FALSE
)
I want to exclude participants whose value "my_video_item_duration_min" is less than 5 and greater than 7. To do so I apply this dplyr code:
myproject_filtered = myproject %>%
filter(my_video_item_duration_min > 5) %>%
filter(my_video_item_duration_min < 7)
Now I want to exclude a participant everytime that futuremw:1 is different from 2 and pastmw:1 is equal to 1 and proportionfuturepast is different from 3 so that I want the participant 4 to be excluded because all the three exclusion criteria at the same time are met. If only 1 or 2 exclusion criteria is met but not the other then the participant is not excluded. Furthermore I want to keep included participant n. 5, even though it presents NA values
I've tried this
myproject_filtered = myproject %>%
filter(my_video_item_duration_min > 5) %>%
filter(my_video_item_duration_min < 7) %>%
filter(futuremw_1 != 2 | pastmw_1 == 1 | proportionfuturepast_1 != 3)
I have used the code proposed in the answer and it works . However, I now want to combine different exclusion criteria. The following code does not work:
myproject_excluding_participants = myproject %>%
filter (
my_video_item_duration_min >= 5,
my_video_item_duration_min <= 7,
! complete.cases(.) | mind_wandering_1 != 1 | proportionMW_1 != 11,
! complete.cases(.) | mind_wandering_1 != 2 | proportionMW_1 == 11,
! complete.cases(.) | futuremw_1 != 2 | pastmw_1 != 2 | proportionfuturepast_1 == 4,
! complete.cases(.) | futuremw_1 != 1 | pastmw_1 != 2 | proportionfuturepast_1 == 1,
! complete.cases(.) | futuremw_1 != 2 | pastmw_1 != 1 | proportionfuturepast_1 == 7,
! complete.cases(.) | futuremw_1 != 1 | pastmw_1 != 1 | proportionfuturepast_1 != 1,
! complete.cases(.) | futuremw_1 != 1 | pastmw_1 != 1 | proportionfuturepast_1 != 7,
! complete.cases(.) | ED_1 != 1 | proportionED_1 != 11
! complete.cases(.) | ED_1 != 2 | proportionED_1 != 11,
! complete.cases(.) | proportionfuturepast_dailylife_1 != 1 | futureMW_dailylife_1 != 5,
! complete.cases(.) | proportionfuturepast_dailylife_1 != 1 | pastMW_dailylife_1 == 5,
! complete.cases(.) | proportionfuturepast_dailylife_1 != 7 | pastMW_dailylife_1 != 5,
! complete.cases(.) | proportionfuturepast_dailylife_1 != 7 | futureMW_dailylife_1 == 5,
! complete.cases(.) | futureMW_dailylife_1 != 5 | pastMW_dailylife_1 != 5 | proportionfuturepast_dailylife_1 == 4,
! complete.cases(.) | CurrentConcernsAreas_14 != 1 | SumCurrentConcernsAreas1to13 < 0
)