library("censusxy")
library(readr)
library(openxlsx)
#Import YOUR OWN .csv file full of addresses here:
sandiego_geocode5 <- read_csv("sandiego_geocode5.csv")
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   STREET = col_character(),
##   CITY = col_character(),
##   STATE = col_character(),
##   ZIP = col_double()
## )
View(sandiego_geocode5)                    
#Here we're asking the US Census API (for the 2020 Census) to send us the geography data for each address- this includes census tract numbers
cxy_geocode(sandiego_geocode5,street  = 'STREET', city = 'CITY', state = 'STATE', zip = 'ZIP',return = 'geographies', benchmark = "Public_AR_Census2020", vintage = 2020, class = 'dataframe', output = 'simple')
## Loading required namespace: sf
##           STREET      CITY STATE   ZIP   cxy_lon  cxy_lat cxy_state_id
## 2 700 LAW STREET SAN DIEGO    CA 92109 -117.2580 32.80199            6
## 1  3800 T STREET SAN DIEGO    CA 92113 -117.1123 32.69890            6
##   cxy_county_id cxy_tract_id cxy_block_id
## 2            73         8003         3006
## 1            73         3502         2006
#Now we'll export the new database we made to Excel for further analysis and cleaning
write.xlsx(sandiego_geocode5, 'sandiego_census.xlsx')