问题描述
structure(list(trip_count = 1:10,pickup_longitude = c(-73.964096,-73.989037,-73.934998,-73.93409,-73.998222,-74.004478,-73.994881,-73.955917,-73.993607,-73.948265),pickup_latitude = c(40.764141,40.760208,40.746693,40.715908,40.750809,40.741501,40.74033,40.776054,40.758625,40.778515)),row.names = c(NA,-10L),class = c("tbl_df","tbl","data.frame"))
因此,我试图将经度和纬度数据重新编码为NYC的邮政编码。
使用revgeocoding
中的ggmap
,我已经得到了一些结果:
res <- revgeocode(c(test$pickup_longitude[1],test$pickup_latitude[1]),output = "all")
但是,
res <- revgeocode(c(test$pickup_longitude,test$pickup_latitude),output = "all")
解决方案不必在ggmap
中工作,也许有其他方法可以从经度和纬度数据中获取邮政编码?
谢谢!
解决方法
我没有API密钥,但是请尝试以下操作:
my_func <- function(longlat,output){
list(list(list(c(vector("list",7),list(12345L)))))
}
test %>%
rowwise() %>%
mutate(zip = list(my_func(c(pickup_longitude,pickup_latitude),output = "all"))) %>%
mutate(zip = zip[[1]][[1]],zip = zip[[8]])
将my_func
替换为revgeocode
。您将必须弄清楚如何从输出中选择邮政编码。但是您可以尝试上述类似方法。