In my dataframe I have over 260K rows. Each individual (ID) has 4 rows, one for every year (2013 - 2016). I've a problem with a column. Each ID is only allowed to have a "0" for 2013 (I already exclude ID's who had a "1" in 2013). In addition, they are only allowed to have a "0" for 2014, 2015 and 2016 (so 3 times a "0") OR have a "1" for 2014, 2015 and 2016 (so 3 times a "1"). If they have a mix of "0" and "1" for 2014, 2015 and 2016, I want to exclude the ID completely.
structure(list(Year = c(2013, 2014, 2015, 2016, 2013, 2014, 2015,
2016, 2013, 2014, 2015, 2016, 2013, 2014, 2015, 2016), Value = c(0,
0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1), ID = c(1, 1, 1,
1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4), Gender = c(0, 0, 0, 0,
0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1)), row.names = c(NA, -16L), class = c("tbl_df",
"tbl", "data.frame"))
tibble [16 x 4] (S3: tbl_df/tbl/data.frame)
$ Year : num [1:16] 2013 2014 2015 2016 2013 ...
$ Value : num [1:16] 0 0 0 0 0 1 1 1 0 1 ...
$ ID : num [1:16] 1 1 1 1 2 2 2 2 3 3 ...
$ Gender: num [1:16] 0 0 0 0 0 0 0 0 1 1 ...
I've already tried some things with filter/subset and |/&; but I couldn't figure it out. There are more columns in my dataframe then showed above. Hopefully someone can help me. Thank you!