0
$\begingroup$

I am looking for a methodology to filter the following data frame so that I end up with only the rows that have a 1 in some column and a 2 in any other column after the column containing the 1. I am thankful for any help!

data_rel1 <- structure(list(job1category = c(NA, 1, 2, 2, 1, 1, 2, 1, 1, 1, 
1, 1, 1, 1, NA, 1, 1, 4, 1, 1, NA, NA, 1, 1, 1, 1, 1, 1, 2, 1, 
1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 6, 1, 1, 1, 1, NA, 7, NA, 5, 1, 
5, NA, 2, 5, 1, NA, 1, 5, 1, 1, 1, 1, 5, 1, 5, 4, 1, 4, 5, 4, 
NA, 5, NA, 5, 4, 3, 6, 1, 4, 4, 5, 4, 1, NA, 1, NA, 1, NA, 1, 
1, 1, 1, 1, 4, 1, 1, 1, NA, 1, NA), job2category = c(3, 2, 1, 
2, 3, 1, 2, 2, 1, 1, 1, NA, 2, 1, NA, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 5, 3, 3, 1, 1, 2, 4, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 
1, 1, 7, 7, 1, 1, 1, NA, 4, 1, 1, NA, 2, 1, 1, 1, 1, NA, 5, NA, 
4, 5, 4, NA, 5, 2, 4, 4, 2, 7, 5, NA, 5, 2, NA, 4, NA, 1, 5, 
NA, 1, NA, 1, 1, 1, 1, 5, 2, NA, 4, 1, 1, 1, NA, 1, NA), job3category = c(3, 
2, 1, 2, 3, 1, 2, 2, 1, 1, 1, NA, 2, 1, NA, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 5, 3, 3, 1, 1, 2, 4, 1, 1, 1, 1, 1, 1, 1, 1, 2, 
2, 1, 1, 1, 7, 7, 1, 1, 1, NA, 4, 1, 1, NA, 2, 1, 1, 1, 1, NA, 
5, NA, 4, 5, 4, NA, 5, 2, 4, 4, 2, 7, 5, NA, 5, 2, NA, 4, NA, 
1, 5, NA, 1, NA, 1, 1, 1, 1, 5, 2, NA, 4, 1, 1, 1, NA, 1, NA), 
    job4category = c(3, 2, 1, 2, 3, 1, 2, 2, 1, 1, 1, NA, 2, 
    1, NA, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 3, 3, 1, 1, 2, 
    4, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 7, 7, 1, 1, 1, 
    NA, 4, 1, 1, NA, 2, 1, 1, 1, 1, NA, 5, NA, 4, 5, 4, NA, 5, 
    2, 4, 4, 2, 7, 5, NA, 5, 2, NA, 4, NA, 1, 5, NA, 1, NA, 1, 
    1, 1, 1, 5, 2, NA, 4, 1, 1, 1, NA, 1, NA)), row.names = c(NA, 
-100L), class = c("tbl_df", "tbl", "data.frame"))
$\endgroup$

Browse other questions tagged or ask your own question.