数据有行= 434,来源= A列,目的地=“445 East 86th Street”,但它给了我一个错误:
Error in `$<-.data.frame`(`*tmp*`, "distance", value = list()) :
replacement has 0 rows, data has 434
我的代码是:
matching_factor <- function(origin){
testData$distance<- list();
xml.url <- paste0('http://maps.googleapis.com/maps/api/distancematrix/xml?origins=',curlEscape(urls=origin),'&destinations=',curlEscape(urls=testData$Address),'&mode=walking&sensor=false')
xmlfile <- xmlParse(getURL(xml.url))
dist <- xmlValue(xmlChildren(xpathApply(xmlfile,"//distance")[[1]])$value)
distance <- as.numeric(sub(" miles","",dist))
distance <- distance/1609.344
testData$distance[['dist']] <- distance
return(testData$distance)
}
matching_factor( origin = "445 East 86th Street")