library(tidycensus) library(tidyverse) tableYear = 2020 #log on with API census_api_key("7a853acf81fd5758228680556ac831138c40b83e") #load variables pueblos = 78 variables = load_variables(2020,"acs5/profile") codes = variables$name label0 = variables$label #view variables #varTable = table(variables$concept) #write.table(varTable, file = "cat.txt", sep = ",", quote = FALSE, row.names = F) #pull all tables with every variable test = get_acs(geography = "county", state = "PR", year = tableYear, variables = codes) #add label column #create empty vector labelCol = c() #amount of GEOIDS for (x in 1:pueblos){ labelCol = c(labelCol, label0) } #combine test and cols test["label"] = labelCol #rearrange cols test = test[c("NAME","label","variable","estimate","moe","GEOID")] GEOIDS = table(test$GEOID) #omit NA rows noNA = na.omit(test) DP02table = noNA %>% filter(startsWith(variable,"DP02")) DP03table = noNA %>% filter(startsWith(variable,"DP03")) DP04table = noNA %>% filter(startsWith(variable,"DP04")) DP05table = noNA %>% filter(startsWith(variable,"DP05"))