0

Packages: ggmap, ggplot2 plyr

I've used a mapdist function to calculate the distance between two postcodes.

I wish to apply the mapdist function to a list and export to a csv. file.

Here is what iv tried.

Run mapdist and export

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")`

I have encountered an Error in match.fun(FUN) :

Any suggestions?

1 Answers1

1

It worked for me (I generated some data):

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
rawr
  • 20,481
  • 4
  • 44
  • 78
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205