R-错误:is.character(location)不是TRUE

时间:2018-07-25 11:05:33

标签: r google-maps csv geocoding

我是R的新手。我在网上找到了一个脚本,该脚本用于对地址列表进行批量地理编码。

http://www.storybench.org/geocode-csv-addresses-r/

但是我一直收到此错误消息“错误:is.character(location)不正确” ...任何人都对如何解决该问题有任何想法?

# Geocoding script for large list of addresses. 
# Finbar Gillen 25/07/2018
#load up the ggmap library
install.packages('ggmap')
library(ggmap)
# Select the file from the file chooser
fileToLoad <- file.choose(new = TRUE)

# Read in the CSV data and store it in a variable
origAddress <- read.csv(fileToLoad, stringsAsFactors = FALSE)

# Initialize the data frame
geocoded <- data.frame(stringsAsFactors = FALSE)

# Loop through the addresses to get the latitude and longitude 
of each address and add it to the
# origAddress data frame in new columns lat and lon
for(i in 1:nrow(origAddress))
{
  # Print("Working...")
  result <- geocode(origAddress$addresses[i], output = 
"latlona", source = "google")
  origAddress$lon[i] <- as.numeric(result[1])
  origAddress$lat[i] <- as.numeric(result[2])
  origAddress$geoAddress[i] <- as.character(result[3])
}
# Write a CSV file containing origAddress to the working 
directory
write.csv(origAddress, "geocoded.csv", row.names=FALSE)

1 个答案:

答案 0 :(得分:0)

在#Print(“正在工作...”)之后 它应该是输入文件/数据框的列名,而不是“地址” 结果<-地理编码(origAddress $ addresses [i],输出= “ latlona”,来源=“ google”)