2017-05-31 10 views
0

私は開始座標と終了座標のdfを持っています。私は、dfのわずかな部分について完全なルートを計算しようとしています。約300回のトリップです。 ggmapのルート関数が始まりますが、約12回のルート計算の後でエラーになります。エラーは(リスト)オブジェクトは強制的に 'double'と入力することはできません。これをコードでどのように修正できますか?誰かがテストするために、以下のリンクにデータのCSVがあります。計算ルート:(リスト)オブジェクトを強制入力することはできません 'double double

最後の目標は、すべてのルートを視覚化する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 

これは、エラーは、GoogleのAPIとあったエラー

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 
+0

問題の内容はわかりませんが、 'route()'では文字入力が必要ですか?たとえば、次のように開始アドレスを読むことができます: 'start <-as.character(feb_14 [1:10、6])'。これによって計算されたルートが生成されますが、long_routesオブジェクトの目標が混乱しています。 – timfaber

+0

私は緯度/経度座標を14番と15番の文字に変換しました。私はString.AsFactors = FALSEをread.csvに追加するのを忘れていました。目標最終製品は、次のようなものです。http://flowingdata.com/2014/02/05/where-people-run/ –

答えて

0

です。私は毎秒のレート制限を打っていました。シンプルな修正は、Sys.Sleepを追加してコールレートを低下させることでした。

calculationroute <- function(startingpoint, stoppoint) { 
Sys.sleep(1) 
    route(from = startingpoint, 
     to = stoppoint, 
     mode = "bicycling", 
     structure = "route")} 
関連する問題