I have a dataframe that looks like this:
Author ID Country Year
A 12345 US 2011
B 13254 Germany 2018
C 54952 Belgium 2005
D 58774 UK 2009
E 88569 Lebanon 2015
...
I want to exclude all countries that are part of the EU and the USA. However, I am having trouble with countries that contain a space, for example Czech Republic and United Kingdom.
I have so far tried using
non_other_countries<-c("Belgium", "Bulgaria", "Demnark", "Germany", "Estonia", "Finland", "France", "Greece", "Ireland", "Italy", "Croatia", "Latvia", "Lithuania", "Luxembourg", "Malta", "Netherlands", "Austria", "Poland", "Portugal", "Romania", "Slovakia", "Slovania", "Spain", "Sweden", "Czech Republic", "Hungary", "United Kingdom", "Cyprus", "United States")
other_post_2011 <- other_post_2011_with_id[, setdiff(names(other_post_2011_with_id), non_other_countries)]
and
other_post_2011 <- subset(other_post_2011_with_id, ! Country %in% c("Belgium", "Bulgaria", "Demnark", "Germany", "Estonia", "Finland", "France", "Greece", "Ireland", "Italy", "Croatia", "Latvia", "Lithuania", "Luxembourg", "Malta", "Netherlands", "Austria", "Poland", "Portugal", "Romania", "Slovakia", "Slovania", "Spain", "Sweden", "Czech Republic", "Hungary", "United Kingdom", "Cyprus", "United States", "USA"))
However, neither were able to exclude countries that contained a space.
I have right now developed a (imo) quite ugly workaround solution by replacing all Czech Republic with Czechia and all United Kingdom with UK by
other_post_2011_with_id$Country[other_post_2011_with_id$Country == "Czech Republic"] <- "Czechia"
other_post_2011_with_id$Country[other_post_2011_with_id$Country == "United Kingdom"] <- "UK"
but I had been wondering if there was any other more elegant and also universal solution to this. Thank you very much!