【问题标题】:R - Error: is.character(location) is not TRUER - 错误:is.character(location) 不是 TRUE
【发布时间】:2018-07-25 11:05:33
【问题描述】:

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

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

但是我不断收到此错误消息“错误:is.character(location) is not TRUE”...有人对如何解决这个问题有任何想法吗??

# 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)

【问题讨论】:

    标签: r google-maps csv geocoding


    【解决方案1】:

    #Print("工作中...") 之后 它应该是您的输入文件/数据框列的名称,而不是“地址” 结果

    【讨论】:

    • 嗨莎玛,谢谢!列名的开头没有大写字母。当地址无法编码时,代码会被中断。你知道我如何修改代码,让它显示“未找到”并继续到下一个地址吗?
    猜你喜欢
    • 2019-10-30
    • 1970-01-01
    • 2018-05-27
    • 1970-01-01
    • 2018-10-26
    • 1970-01-01
    • 2017-04-07
    • 2015-08-27
    • 2023-04-03
    相关资源
    最近更新 更多