I want to filter a dataframe using dplyr using a conditional. The condition I want to test is whether a country-year combination has two versions.
df <- data.frame(country = c("country1", "country2", "country1", "country2", "country3"), year = rep(2011,5), version = c("versionA", "versionA", "versionB", "versionB", "versionB"))
Here is what I tried after looking here:
df %>%
group_by(country, year) %>%
{if unique(version)==1 . else filter(version == "versionA")}
What I am hoping to get is a dataframe that looks like this:
country year version
country1 2011 versionA
country2 2011 versionA
country3 2011 versionB