Tmap Error - replacement has [x] rows, data has [y]

天涯浪子 提交于 2019-12-02 08:37:41

Your error is in the data - the code works fine.

What you are doing right now is:

1) attempting a 1:1 match

2) realize that your .csv data contains several ids to match

3) a left-join then multiplies the left hand side with all matches on the right hand-side

To avoid this issue you have to aggregate your data one more time like:

library(dplyr)

df_unique = df %>%
    group_by(country_code, country_name) %>%
    summarize(total = sum(total), freq = sum(freq))


#after that you should be fine - as long as just adding up the data is okay.
countries@data = left_join(countries@data, df, by = c("iso_a2" = 
"country_code"))

qtm(countries, "freq")
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!