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

前端 未结 1 1720
鱼传尺愫
鱼传尺愫 2021-01-28 09:49

Short version: when executing the following command qtm(countries, \"freq\") I get the following error message:

Error in

相关标签:
1条回答
  • 2021-01-28 10:34

    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")
    
    0 讨论(0)
提交回复
热议问题