Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R Tmap错误-替换有[x]行,数据有[y]_R_Tmap - Fatal编程技术网

R Tmap错误-替换有[x]行,数据有[y]

R Tmap错误-替换有[x]行,数据有[y],r,tmap,R,Tmap,简短版本:当执行以下命令时qtm(countries,“freq”)我收到以下错误消息: $中出错您的错误在数据中-代码工作正常 您现在正在做的是: 1) 正在尝试1:1的比赛 2) 请意识到.csv数据包含多个要匹配的ID 3) 然后,左连接将左侧与右侧的所有匹配项相乘 要避免此问题,您必须再次聚合数据,如: library(dplyr) df_unique = df %>% group_by(country_code, country_name) %>% sum

简短版本:当执行以下命令时
qtm(countries,“freq”)
我收到以下错误消息:


$中出错您的错误在数据中-代码工作正常

您现在正在做的是:

1) 正在尝试1:1的比赛

2) 请意识到.csv数据包含多个要匹配的ID

3) 然后,左连接将左侧与右侧的所有匹配项相乘

要避免此问题,您必须再次聚合数据,如:

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")

非常感谢您的解释和回答。它正在工作!我担心,尽管我认为我已经理解了我的问题所在(左数据帧上有一个变量与右数据帧上的多个变量相匹配,因此,我需要在右数据帧上对变量进行分组),但我仍然面临着同样的信息,但我非常确定问题是另一个问题。如果您愿意回答,我在这里发布了另一个问题:。对不起,如果我问得太多了@Christian
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")