Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.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表示的纬度和经度坐标_R_Google Maps - Fatal编程技术网

以R表示的纬度和经度坐标

以R表示的纬度和经度坐标,r,google-maps,R,Google Maps,我有一列组合的经纬度坐标,格式如下: coordinates (-73.2566,44.51513) 我正在尝试获取格式 lat long 73.2566 44.51512 我知道这似乎是一个相对简单的问题,但我似乎找不到解决办法。我尝试过使用gsub()函数,但这并没有消除括号 > library(stringr) > library(magrittr) > "(-73.2566, 44.51513)" %>% # take coord as string

我有一列组合的经纬度坐标,格式如下:

coordinates
(-73.2566,44.51513)
我正在尝试获取格式

lat     long
73.2566  44.51512
我知道这似乎是一个相对简单的问题,但我似乎找不到解决办法。我尝试过使用gsub()函数,但这并没有消除括号

> library(stringr)
> library(magrittr)
> "(-73.2566, 44.51513)" %>% # take coord as string
+   str_replace_all("[()]", "") %>% # replace parantheses
+   str_split_fixed(", ", n=2) %>% # split up based on comma and space after
+   as.data.frame %>% # turn this to a data frame
+   transmute(lat=V1, long=V2) # rename the variables
       lat      long
1 -73.2566  44.51513
如果您有一个这些值的向量,可以通过对(i in coords)执行此操作来轻松调整,其中末尾的
data.frame
将使用类似于
bind\u rows
的方法重复添加到数据集


如果你有一个这些值的向量,可以通过为(i in coords)做这个
来很容易地调整它,其中末尾的
data.frame
将使用类似于
bind_rows

的东西重复添加到数据集中,使用这个简单的函数(需要使用google api):


google\u-api尝试使用这个简单的函数(需要使用google-api):


这可能有点太简单了,但是

> coordinates=c(-73.2566,44.51513)
> coordinates
[1] -73.25660  44.51513
> lat=coordinates[1]
> lat
[1] -73.2566
> long=coordinates[2]
> long
[1] 44.51513

有一个ggmap包,这可能有点太简单了,但是

> coordinates=c(-73.2566,44.51513)
> coordinates
[1] -73.25660  44.51513
> lat=coordinates[1]
> lat
[1] -73.2566
> long=coordinates[2]
> long
[1] 44.51513

这里有一个ggmap包,使用
pattern=“\\(\\\”
,然后用
replacement=“
”替换gsub,然后用
strsplit
”,“
”,作为旁白(因为你已经用
google maps
标记了这个问题)我已经构建了通过R访问Google Maps API的包。请参见示例。使用
模式=“\\”(\124;\\”
,然后使用gsub的
替换=“
”,然后使用
strsplit
,“
”。作为旁白(因为您已经用
Google Maps
标记了这个问题)我已经建立了通过R访问Google Maps API的软件包。请参阅示例。我对使用已经提供的点更感兴趣,但感谢您提供的这个有用的功能,下次我只有地址时肯定会使用。Lorenzo,你这个天才!我对使用已经提供的点更感兴趣,但感谢您提供的这一有用的乐趣下次我只有地址的时候我肯定会用的。洛伦佐,你这个天才!谢谢你这非常有帮助我知道这比我想象的要简单哈哈。谢谢你这非常有帮助我知道这比我想象的要简单哈哈。谢谢你把它保存到我的桌面上作为将来的参考!谢谢你的gr吃备忘保存到我的桌面,以备将来参考!