Hi, im new to R and Rcommunity.
m trying to get blockgroups for my dataset that has geocodes:
The issue I am facing is bizarely when my dataset has 1k rows I receive an output with a column for blockgroup but when I increase my dataset to 3k or more I do not receive any output of blockgroups and get the below errors of subscript out of bounds and replacement has less rows than data(see below)
Is there something wrong with my FOR loop?
library(tigris)
library(plyr)
library(dplyr)
setwd("C:/Users/bb/Desktop/ Study/Experimental")
> MyData <- read.csv(file="AddressMaster18k.csv", header=TRUE, sep=",")
>
> lat_tigris <- MyData$Latitude
> lon_tigris <- MyData$Longitude
>
> blockgroup <- c()
>
> for ( i in 1:length(lat_tigris)){
+ block <- call_geolocator_latlon(lat_tigris[i], lon_tigris[i])
+ blockgroup[i] <- substr(block,1,nchar(block)-3)
+ #cat(paste(i," => ", blockgroup))
+ }
Error in response$result$geographies```
2010 Census Blocks`[[1]] :
subscript out of bounds
>
> MyData["blockgroup"] <- as.character(blockgroup)
Error in `[<-.data.frame`(`*tmp*`, "blockgroup", value = c("360810437012", :
replacement has 668 rows, data has 6000
> head(MyData)
AddressId StreetAddressLine1 City ZipCode StateAbbreviation Latitude
1 6958258 58-19 Waldron Street Corona 11368 NY 40.73910
2 6958302 1309 East Main St Greenwich 6830 CT 41.54827
3 6958268 98607 Kilinoe Street Aiea 96701 HI 21.39609
4 6958277 267 E. 7th Street New York 10009 NY 40.72346
5 6958279 2444 Grassy Br Rd Raccoon 41557 KY 37.51309
6 6958280 940 Nw Frecro Way Jensen Beach 34957 FL 27.23904
Longitude GeocodeSource MatchDescription
1 -73.85216 arcgis NA
2 -73.01996 arcgis NA
3 -157.93812 arcgis NA
4 -73.97732 arcgis NA
5 -82.41312 arcgis NA
6 -80.24555 arcgis NA