我有一列组合的纬度和经度坐标,格式如下:
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
如果您有这些值的向量,则可以通过执行此操作轻松进行调整,for (i in coords)
其中data.frame
末尾将使用类似bind_rows
.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句