r - 如何使用 full_join 将 sf 地图数据与 tibble 数据连接起来?
问题描述
我正在尝试将来自 rnaturalearth 的地图数据与 tibble 连接起来。
这是我的小标题的一部分:
structure(list(iso3_code = c("AFG", "AFG", "ALB", "ALB", "DZA",
"ASM"), country = c("Afghanistan", "Afghanistan", "Albania",
"Albania", "Algeria", "American Samoa"), item = c("Maize", "Sugar cane",
"Maize", "Soybeans", "Maize", "Sugar cane"), value = c(106670,
25421, 391104, 744, 4142, 30)), row.names = c(NA, -6L), class = c("tbl_df",
"tbl", "data.frame"))
这是我正在使用的代码:
library(rnaturalearth)
world <- ne_countries(scale = "small", returnclass = "sf")
world_filtered = world %>%
select(country = name_long, iso3_code = iso_a3, geometry) %>%
filter(!is.na(iso3_code)) %>%
filter(country != "Antarctica")
map = full_join(world_filtered, country_data, by = "iso3_code")
我收到此错误:
Error: All columns in a tibble must be vectors.
x Column `geometry` is a `sfc_MULTIPOLYGON/sfc` object.
Run `rlang::last_error()` to see where the error occurred.
我知道我之前已经运行过这段代码并且它有效。我最近刚刚做了一些更新,也许这可能会影响这段代码。如果有人知道这里发生了什么,将不胜感激。
解决方案
我最近也遇到了这个问题。
这是因为tidyverse
(基于tibble
)无法识别sfc_MULTIPOLYGON/sfc
对象。
解决方案是:
library(sf)
推荐阅读
- r - rcppRoll n = 月数而不是 obs
- python - errno 12“无法分配内存”的 MemoryError 和 OSError 之间的区别?
- python - Matplot lib x 轴高分辨率
- java - 如何打开 Java .jps 文件?
- javascript - 对话框流单元测试的 Firebase 函数未返回
- corda - Corda Enterprise 3.2 无法加载自定义配置文件
- eclipse - 休眠 OGM mongodb 示例
- oracle - 查找序列在删除之前生成的最后一个数字
- variables - 模拟重复二元测量的数据
- java - 如何根据输入行的多个条件从扫描仪输入中读取预定义的行数