0

I have a data frame like MyData below:

country <- c("Gr","Gr","Gr","It","It","Eg","Eg","Li")
continent <- c("Eu",NA,NA,"Eu",NA,"Af",NA,"Af")
SomeData <- c(3,1,5,6,2,8,2,9)
MyData <- data.frame(Country=country, Continent=continent, Data=SomeData)

As you can see, the continent of Greece is Europe in some places, but is NA in most of the places. The same with Egypt and other countries of the real data frame. I want to replace the NAs with the name of the country's continent, as it is named in the data frame (Eu, Af, etc).

Is it possible?

Thanks in advance!

PS1: I read this and this. None of them answers my question. PS2: I have too many countries' names to manage.

0 Answers0