【问题标题】:Error in match.fun(FUN) :match.fun(FUN) 中的错误:
【发布时间】:2014-10-06 08:37:56
【问题描述】:

包: ggmap, ggplot2 plyr

我使用了 mapdist 函数来计算两个邮政编码之间的距离。

我希望将 mapdist 函数应用于列表并导出到 csv。文件。

这是 iv 尝试过的。

运行 mapdist 并导出

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) 中遇到错误:

有什么建议吗?

【问题讨论】:

  • 这可能是您的另一个选择。链接是here
  • 你能让你的问题重现吗?

标签: r lapply ggmap


【解决方案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

【讨论】:

  • 这意味着 OP 忘记加载库。
猜你喜欢
  • 2012-07-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-28
  • 1970-01-01
  • 2020-12-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多