我该如何解决:响应$result$geographies$`2010 Census Blocks`[[1]] 错误:latitude/longitude 数据的下标越界

How do I fix: Error in response$result$geographies$`2010 Census Blocks`[[1]] : subscript out of bounds for latitude/longitude data

Update: 所以在我的数据集中,其中一个坐标集是(49.277298, -123.067902),而且不仅是唯一一个越界,也是唯一一个一个对分析造成严重破坏。希望这个补充对您有所帮助!

我正在努力为仅列出纬度和经度但在响应$result$geographies$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))
}

然后我也用了一个apply:

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)

两个return 响应错误 $result$geographies$2010 Census Blocks[[1]] : 下标越界

您应该可以通过使用 ifelse() 来避免循环,如:

ifelse( is.na(census$locationlatitude),  
        NA, 
        call_geolocator_latlon(census$locationlatitude, census$locationlongitude)
       )

这假设 call_geolocator_latlon 是向量化的。