有条件的列值计算,邮政编码到lat/long

发布于 2025-01-24 17:42:55 字数 2015 浏览 5 评论 0原文

我需要帮助尝试在R中弄清楚如何做到这一点。我不知道如何从邮政编码数据中产生纬度和经度,因此我被困在第一部分。

我有一个看起来像:

ID邮政编码1邮政编码LOC 2邮政编码邮政编码3邮政编码邮政编码3
190804917239081491604中立3

我试图添加三个列,看起来这样:

ID邮政编码LOC 1邮政编码LOC 2邮政编码LOC 3邮政编码在LOC 1上对LOC 2意见的loc 2意见在LOC 3距离距离远距离距离距离距离距离距离距离距离距离距离距离距离为
290804917239081491604中性喜欢42 56km24 km

我只有邮政编码数据,我试图知道是否有一种方法可以为经度和纬度创建列,以便可以计算距离。

之后,需要创建的列需要首先匹配哪个位置“喜欢”的位置,计算其与之的距离,然后将距离放在“距离距离”列的“距离”等等。

I need help trying to figure out how to do this in R. I don't know how to generate latitude and longitude from zip code data so I am stuck on the first part.

I have a df that looks like:

IDZIP codeloc 1 zip codeloc 2 zip codeloc 3 zip codeOpinion on loc 1Opinion on loc 2Opinion on loc 3
190804917239081491604NeutralLikeDislike

I am trying to add three columns that look like this:

IDZIP codeloc 1 zip codeloc 2 zip codeloc 3 zip codeOpinion on loc 1Opinion on loc 2Opinion on loc 3Distance from LikeDistance from DisikeDistance from Neutral
190804917239081491604NeutralLikeDislike42 Km56 Km24 Km

I only have the zip code data, I am trying to know if there is a way to create columns for longitude and latitude so that distance calculation is possible.

After that, the columns that need to be created need to first match which location does the customer 'Like', calculate their distance from it, and then put the distance in the 'Distance from Like' column and so on.

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

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

发布评论

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

评论(1

箹锭⒈辈孓 2025-01-31 17:42:55

如果是美国Zipcodes,请使用库ZipCoder,直接允许您计算邮编之间

library(zipcodeR)
zip_distance(zipcode_a, zipcode_b, lonlat = TRUE, units = "meters")

If it are USA zipcodes, use library zipcodeR which directly allows you to calculate distances between zipcodes

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