I have a dataset like this -
tibble(
year = c (2005, 2005, 2005,
2006, 2006, 2006,
2007,2007,2007),
var1 = c (2136,2136,2136,
2285,2285,2285,
2968,2968,2968),
var2 = c (125860,1318,127464,
8972,2136,5046,
4739,1619,10063)
)
I want to filter the dataset like this -
first group by the data by variables year and var1, then compare columns var1 and var2,
if it is found that the values in columns var1 and var2 match, then I want to filter all of them.
For the example dataset, if we look, we can see in var1 2136 in 2005 matches with 2136 in var2 in 2006. therefore, I would like to filter both 2005 and 2006 rows because in both columns var1 and var2, they have a common value - 2136.
So the expected resulted will look like this -
tibble(
year = c (2005, 2005, 2005,
2006, 2006, 2006
),
var1 = c (2136,2136,2136,
2285,2285,2285),
var2 = c (125860,1318,127464,
8972,2136,5046)
)
Can anybody help?