這裏是我的重複性代碼:如何國家代碼轉換成國名
library(tidyverse)
library(eurostat)
library(countrycode)
#Query eurostat data set
search <- search_eurostat("road", type = "table")
#Accessing "People killed in road accidents" data set.
df <- get_eurostat("tsdtr420")
#Create a data frame filtered on most recent data (2015)
accidents2015 <- df %>%
filter(time == "2015-01-01")
codes <- select(accidents2015, geo)
countrycode(sourcevar = codes, "iso2c", "country_name")
當最後一個行運行我收到此錯誤信息:
條件具有長度> 1,只有第一元素將在countrycode中使用錯誤(sourcevar = codes,「iso2c」,「country_name」): sourcevar必須是字符或數字向量。
非常感謝!你給出了最好的答案! – Tdebeus