加入形状文件和CSV文件而不会丢失/获得数据

发布于 2025-02-02 12:41:32 字数 252 浏览 5 评论 0原文

我正在尝试加入一个.shp文件(对小区域多边形的2644个观察结果),其中一些小区域的每月数据观察到每月数据的7,760个观察结果),以在R中创建交互式传单映射。我尝试使用使用。从图书馆(Tigris)的地理名录,如果我在小区域上进行左联接或17,088个观察,则只能获得2,644个观察结果,如果我在小区域内进行内部连接。使用库(DPLYR)出现了类似的问题。您是否有关于如何执行此加入的建议,而不会丢失.CSV文件中的任何数据并重复.CSV中重复的小区域的形状多边形,因为数据每月重复?

I am trying to join a .shp file (2644 Observations of small region polygons) with a .csv file (7,760 observations of monthly data for some of these small regions) in order to create an interactive leaflet map in R. I have tried using geojoin from library(tigris) and end up with only 2,644 observations if I do a left join on small region or 17,088 observations if I do an inner join on small regions. Similar issues arise using library(dplyr). Do you have any recommendations on how to perform this join without losing any of the the data from the .csv file and repeating the shape polygons for repeated small regions within the .csv as the data repeats monthly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

童话 2025-02-09 12:41:32

您随时可以共享这样的虚拟数据,我已经正确理解了您的数据:

shpfile =data.frame(region=rep(paste("Place",1:4),each=3),coord=sample(1:100,12))

csvfile = data.frame(region=rep(paste("Place",1:4),each=12),months= rep(month.abb,4),val=sample(1:100,48))

library(dplyr)
df1= merge(shpfile,csvfile,by="region",all.y=TRUE)
df1

You can always share a dummy data like this, Asssuming I have understood your data correctly:

shpfile =data.frame(region=rep(paste("Place",1:4),each=3),coord=sample(1:100,12))

csvfile = data.frame(region=rep(paste("Place",1:4),each=12),months= rep(month.abb,4),val=sample(1:100,48))

library(dplyr)
df1= merge(shpfile,csvfile,by="region",all.y=TRUE)
df1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文