有条件的列值计算,邮政编码到lat/long
我需要帮助尝试在R中弄清楚如何做到这一点。我不知道如何从邮政编码数据中产生纬度和经度,因此我被困在第一部分。
我有一个看起来像:
ID | 邮政编码 | 1邮政编码 | LOC 2邮政编码 | 邮政编码 | 的 | 3邮政编码 | 邮政编码3 |
---|---|---|---|---|---|---|---|
1 | 90804 | 91723 | 90814 | 91604 | 中立 | , | 3 |
我试图添加三个列,看起来这样:
ID | 邮政编码 | LOC 1邮政编码 | LOC 2邮政编码 | LOC 3邮政编码 | 在LOC 1上 | 对LOC 2意见的loc 2意见 | 在LOC 3 | 距离距离远距离 | 距离距离距离距离距离距离 | 距离距离距离距离距离为 |
---|---|---|---|---|---|---|---|---|---|---|
2 | 90804 | 91723 | 90814 | 91604 | 中性 | 喜欢 | 不 | 42 56 | km | 24 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:
ID | ZIP code | loc 1 zip code | loc 2 zip code | loc 3 zip code | Opinion on loc 1 | Opinion on loc 2 | Opinion on loc 3 |
---|---|---|---|---|---|---|---|
1 | 90804 | 91723 | 90814 | 91604 | Neutral | Like | Dislike |
I am trying to add three columns that look like this:
ID | ZIP code | loc 1 zip code | loc 2 zip code | loc 3 zip code | Opinion on loc 1 | Opinion on loc 2 | Opinion on loc 3 | Distance from Like | Distance from Disike | Distance from Neutral |
---|---|---|---|---|---|---|---|---|---|---|
1 | 90804 | 91723 | 90814 | 91604 | Neutral | Like | Dislike | 42 Km | 56 Km | 24 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果是美国Zipcodes,请使用库ZipCoder,直接允许您计算邮编之间
If it are USA zipcodes, use library zipcodeR which directly allows you to calculate distances between zipcodes