I'm trying to see if I can use a loop using apply or purrr functions to loop through columns to filter the same data value. For example, I'm looking for a way to loop through columns Q2_1:Q2_10. Currently, I'm doing this in a highly inefficient way:
data %>%
filter(Q2_1 == 5) %>%
filter(Q2_2 == 5) %>%
filter(Q2_3 == 5) %>%
filter(Q2_4 == 5) %>%
filter(Q2_5 == 5) %>%
filter(Q2_6 == 5) %>%
filter(Q2_7 == 5) %>%
filter(Q2_8 == 5) %>%
filter(Q2_9 == 5) %>%
filter(Q2_10 == 5)
I'm not sure how to get started with the lapply or with the tidyverse way. Should I convert the filter into a function or just add the filter function into the loop?