country <- c("USA","UK","Egypt","Brazil","USA", "UK")
continent <- c("North America","Europe","Africa","South America", NA, NA)
data.frame(country, continent)
How do I automatically impute those last two NAs based on the previous rows since we know that "USA" goes with "North America" and "UK" goes with "Europe"?
I have a large dataset so it would be super helpful if I could find a quick way to do this in dplyr when there are many NAs.
Thank you in advance!