因此,我試圖使用ggmap的route()函數來創建一個可以疊加到地圖上的幾何圖形。使用ggmap路由功能的列表錯誤
我有一個名爲「lat,lon」格式的列表,名爲checkpoints。
list("40.775912, -74.012619", "40.775912, -74.012619", "40.782669, -74.008143",
"40.788587, -74.000447", "40.805952, -73.991671", "40.821177, -73.987895",
"40.836634, -73.978271", "40.845806, -73.971319", "40.855106, -73.967628",
"40.859186, -73.972037", "40.862502, -73.969255", "40.863977, -73.968383",
"40.860894, -73.968126", "40.856154, -73.972603", "40.852727, -73.965511",
"40.850897, -73.965913", "40.850939, -73.968064", "40.846506, -73.970819",
"40.836634, -73.978271", "40.821177, -73.987895", "40.806622, -73.991894",
"40.788587, -74.000447", "40.782669, -74.008143", "40.775912, -74.012619")
我試着以1-2 2-3隨後即在每個組的位置執行路由功能...
routes <- lapply(2:length(checkpoints),
function(x) route(from = checkpoints[[x-1]],
to = checkpoints[[x]],
mode = "driving",
output = "simple"))
的代碼運行,直到每次10步然後我得到這個錯誤:
Error: (list) object cannot be coerced to type 'integer'
我風與10個條目的路由數據的方式的名單,我想它再沒有別的。我已經嘗試在apply函數中列出檢查點列表,並且無論出於何種原因,它仍然沒有超過第10步。任何幫助,將不勝感激。也請原諒格式或禮儀的任何錯誤,這基本上是我的第一個問題。
seconding @Axeman,我會包含一個數據集讓我們看看這裏;你也可以打印第10欄,看看有什麼特別的。最後;在這種情況下,我總是推薦作弊;強制列表成爲數據表a la checkpoints < - as.data.table(as.character(檢查點)),然後再給它一次。 – ike