包裹: ggmap, GGPLOT2 普莱尔
我使用了mapdist函数来计算两个邮政编码之间的距离。
我希望将mapdist函数应用于列表并导出到csv。文件。
这是iv试过的。
data <- mutate(dataset, from = NA, to = NA, m = NA, km = NA, miles = NA)
lapply(dataset, mapdist(PostcodeA, PostcodeB, mode = "driving"))
Error in match.fun(FUN) :
'mapdist(PostcodeA, PostcodeB, mode = "driving")' is not a function, character or symbol
dataset <- data.frame(lapply(dataset, as.character))
write.csv(dataset, "Rexport.csv")`
我在match.fun(FUN)遇到错误:
有什么建议吗?
答案 0 :(得分:1)
它对我有用(我生成了一些数据):
library(rvest)
library(stringr)
# get America's most expensive zip codes
pg <- html("http://www.forbes.com/2009/08/26/most-expensive-zip-codes-lifestyle-real-estate-zip_full-list.html")
zips <- pg %>% html_nodes("td a") %>% html_text() %>% str_extract("[[:digit:]]+")
from <- head(zips)
to <- tail(zips)
data_set <- mapdist(from, to, mode="driving")
data_set
## from to m km miles seconds minutes hours
## 1 07620 95054 4733283 4733.283 2941.26206 151391 2523.18333 42.0530556
## 2 94027 95148 48750 48.750 30.29325 2464 41.06667 0.6844444
## 3 10014 95060 4787194 4787.194 2974.76235 154148 2569.13333 42.8188889
## 4 91008 94089 581823 581.823 361.54481 19609 326.81667 5.4469444
## 5 90210 63124 2949509 2949.509 1832.82489 92594 1543.23333 25.7205556
## 6 92067 02714 4892815 4892.815 3040.39524 157615 2626.91667 43.7819444