我刚刚发现还有一个名为“raster”的包,其中包含更详细的大陆信息,可以用来代替“countrycode”。使用 (countrycode),也可以单独指定某些国家/地区。
它甚至允许在更详细的区域之后进行分组。
两个包的示例:
# Assigning continents to country codes
library(countrycode)
iso2c_to_continents <- c(CA = "North America" , US = "North America")
c <- countrycode(sourcevar = yourdf[["ISO Code"]], origin = "iso2c", destination = "continent",custom_match = iso2c_to_continents)
yourdf <- cbind(yourdf, c)
# if the destination should be a more detailed region, little different:
c.2 <- countrycode(sourcevar = yourdf[["ISO Code"]], origin = "iso2c", destination = "region")
yourdf <- cbind(yourdf, c.2)
# Another package could be used as well
library(raster)
yourdf <- merge(yourdf,ccodes()[,c("ISO2","continent")],by.x=,by.y=)
# or
yourdf <- merge(yourdf,ccodes()[,c("ISO2","UNREGION1")],by.x=,by.y=)