首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >计算路线:(列表)对象不能被强制输入'double‘

计算路线:(列表)对象不能被强制输入'double‘
EN

Stack Overflow用户
提问于 2017-05-31 13:37:18
回答 1查看 593关注 0票数 1

我有一个开始和结束坐标的df。我试着计算出df的一小部分,大约300次行程的全程。ggmap路由函数开始运行,但在大约12次路由计算后出现错误。错误是(列表)对象不能强制输入'double'。我如何在代码中解决这个问题?我有一个csv的数据在下面的链接,供任何人测试。

总体的最终目标是像这个http://flowingdata.com/2014/02/05/where-people-run/这样的产品,可视化所有的路线。

代码语言:javascript
复制
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

这是错误

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-31 14:29:23

错误发生在Google上。我达到了每秒的速率限制。简单的解决方法是添加一个Sys.Sleep来降低呼叫速率。

代码语言:javascript
复制
calculationroute <- function(startingpoint, stoppoint) {
 Sys.sleep(1)
  route(from = startingpoint,
        to = stoppoint,
        mode = "bicycling",
        structure = "route")}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44286328

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档