更新:所以在我的数据集中,其中一个坐标集是(49.277298,-123.067902(,它不仅是唯一一个越界的坐标集,也是唯一一个对分析造成严重破坏的坐标集。希望这个补充能有所帮助!
我正在为一个只列出纬度和经度但不断得到响应错误$result$geographics$2010 Census Blocks
[[1]的数据集寻找人口普查代码:下标越界
当我使用for循环时:
ids <- c()
for(i in 1:nrow(census)){
if(is.na(census$locationlatitude[i])){
id <- NA
} else {
id <- call_geolocator_latlon(census$locationlatitude[i], census$locationlongitude[i])
}
ids <- c(ids, (id))
}
然后我还使用了一个应用程序:
census <- read.csv("census_tract.csv")
census <- census[,c(1:3)]
census$rowid <- 1:nrow(census)
censusNA <- na.omit(census)
censusNA$census_tract <- apply(censusNA, 1, function(row)
call_geolocator_latlon(row['LocationLatitude'], row['LocationLongitude']))
censusNA <- censusNA[,c(3,4)]
census_tract <- merge(census, censusNA, by = "rowid", all.x = TRUE)
两个返回响应$result$geographics$2010 Census Blocks
[[1]]中出错:下标越界
您应该能够通过使用ifelse()
来避免循环,如:
ifelse( is.na(census$locationlatitude),
NA,
call_geolocator_latlon(census$locationlatitude, census$locationlongitude)
)
这假设call_geolocator_latlon
被矢量化。