0
我有一個開始和結束座標的df。我試圖計算df的一小部分的全部路線,大約有300次旅行。 ggmap路由功能開始,但在大約12次路由計算後會出現錯誤。錯誤是(列表)對象不能被強制鍵入'雙'。我該如何解決這個問題?我有一個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
不確定問題出在哪裏,但是'route()'不需要字符輸入?我可以使用例如'start <-as.character(feb_14 [1:10,6])'來讀取開始地址''。這會產生calculatedroutes,但我很困惑long_routes對象的目標是什麼。 – timfaber
我將Lat/Long座標轉換爲列14和15中的字符。我忘了在read.csv中添加StringsAsFactors = FALSE。目標最終產品是這樣的http://flowingdata.com/2014/02/05/where-people-run/ –