【问题标题】:R: Countrycode package not supporting regex as the originR:国家代码包不支持正则表达式作为来源
【发布时间】:2017-02-10 08:11:04
【问题描述】:

我有一个需要转换为标准化格式 (iso3c) 的国家/地区列表。有些名字很长,有些有 2 位或 3 位数字代码,还有一些不显示整个国家/地区名称,例如“非洲”而不是“南非”。我做了一些研究并想在 R 中使用 countrycode 包。但是,当我尝试使用“正则表达式”时,R 似乎无法识别它。我收到以下错误:

> countrycode(data,"regex","iso3c", warn = TRUE)
Error in countrycode(data, "regex", "iso3c",  : 
Origin code not supported

我还需要做什么?

谢谢!

【问题讨论】:

标签: regex r country-codes


【解决方案1】:

您可以在此处https://github.com/vincentarelbundock/countrycode 查看国家/地区代码包的自述文件,或者您可以通过将其输入 R 控制台?countrycode::countrycode 来提取 R 中的帮助文件。

"regex" 不是有效的 'origin' 值(countrycode() 函数中的第二个参数)。您必须使用“cowc”、“cown”、“eurostat”、“fao”、“fips105”、“imf”、“ioc”、“iso2c”、“iso3c”、“iso3n”、“p4_ccode”、“ p4_scode”、“un”、“wb”、“wb_api2c”、“wb_api3c”、“wvs”、“country.name”、“country.name.de”(使用最新版本 0.19)。

如果您使用以下任一 'origin' 值,将自动执行正则表达式匹配:“country.name”或“country.name.de”

如果您使用带有新(自 0.19 版)custom_dict 参数的自定义字典,则必须将 origin_regex 参数设置为 TRUE 以进行正则表达式匹配。

在您的示例中,这应该可以满足您的要求: countrycode(data, origin = "country.name", destination = "iso3c", warn = TRUE)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-01
    • 1970-01-01
    • 2020-07-22
    • 2012-10-03
    • 1970-01-01
    • 1970-01-01
    • 2013-11-18
    相关资源
    最近更新 更多