I have a larger data frame that contains 5 years of data. I'd like to remove rows that are duplicated for a given year without removing those rows from later years. Here is an example.
Year Color X Y
2014 red 1 3
2014 red 1 3
2014 blue 1 3
2015 red 1 3
2015 blue 1 3
2015 yellow 1 3
In this example, I'd like to remove the duplicated row for Year 2014 Color Red, without removing the row for 2015 red. I tired the following code:
df <- df[!duplicated(Color), by = (Year)]
This code removes the duplicated 2014 red, but also the 2015 blue and 2015 red.