我有一个开始和结束坐标的df。我试着计算出df的一小部分,大约300次行程的全程。ggmap路由函数开始运行,但在大约12次路由计算后出现错误。错误是(列表)对象不能强制输入'double'。我如何在代码中解决这个问题?我有一个csv的数据在下面的链接,供任何人测试。
总体的最终目标是像这个http://flowingdata.com/2014/02/05/where-people-run/这样的产品,可视化所有的路线。
library(tidyverse)
library(ggmap)
feb_14 <- read.csv('https://raw.githubusercontent.com/smitty1788/Personal-Website/master/dl/CaBi_Feb_2017.csv', stringsAsFactors = FALSE)
start<-c(feb_14[1:300, 14])
dest<-c(feb_14[1:300, 15])
routes <- tibble(
start,
dest)
calculationroute <- function(startingpoint, stoppoint) {
route(from = startingpoint,
to = stoppoint,
mode = 'bicycling',
structure = "route")}
calculatedroutes <- mapply(calculationroute,
startingpoint = routes$start,
stoppoint = routes$dest,
SIMPLIFY = FALSE)
do.call(rbind.data.frame, lapply(names(calculatedroutes), function(x) {
cbind.data.frame(route=x, calculatedroutes[[x]], stringsAsFactors=FALSE)
})) -> long_routes这是错误
Error in route(from = startingpoint, to = stoppoint, mode = "bicycling", :
(list) object cannot be coerced to type 'double'
Called from: route(from = startingpoint, to = stoppoint, mode = "bicycling",
structure = "route")
Browse[1]>
do.call(rbind.data.frame, lapply(names(calculatedroutes), function(x) {
+ cbind.data.frame(route=x, calculatedroutes[[x]], stringsAsFactors=FALSE)
+ })) -> long_routes发布于 2017-05-31 14:29:23
错误发生在Google上。我达到了每秒的速率限制。简单的解决方法是添加一个Sys.Sleep来降低呼叫速率。
calculationroute <- function(startingpoint, stoppoint) {
Sys.sleep(1)
route(from = startingpoint,
to = stoppoint,
mode = "bicycling",
structure = "route")}https://stackoverflow.com/questions/44286328
复制相似问题