0

I have a dataset with a column "country" abbreviated, and an other dataset with the country full name correspondind like that :

FR France GR Germany CH China IT Italia ES Spain

I would like to know if it was possible to replace in the column "country" the abbreviation by the country full name using this table, without use a loop ?

I already tried to merge and join but i lose data, because some rows in my dataset have not always a country information, and i don't want to lose rows, and if possible not use a loop. I think it's possible but i don't know..

if someone know something about that

Aurélien
  • 103
  • 3
  • 12
  • Please provide some sample data and your desired output. From your description its unclear what your data looks like. – Taran Dec 04 '17 at 15:23
  • You want a "left join" aka "left outer join". In base R, use`merge(your_dataset, your_other_data_with_country_full_name, all.x = TRUE)`. [see this FAQ for R details](https://stackoverflow.com/a/1300618/903061), or [see this FAQ for an explanation of join types](https://stackoverflow.com/a/16598900/903061). – Gregor Thomas Dec 04 '17 at 15:30
  • You might want to try using the [countrycode](https://github.com/vincentarelbundock/countrycode) package. "CH" usually stands for Switzerland, not China (in iso2c anyway). `library(countrycode); countrycode(c("FR", "GR", "CH", "IT", "ES"), "iso2c", "country.name"); countrycode(c("France", "Germany", "China", "Italy", "Spain"), "country.name", "iso2c")` – CJ Yetman Dec 18 '17 at 15:27

0 Answers0