No Description

R.R 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. library(tidycensus)
  2. library(tidyverse)
  3. tableYear = 2020
  4. #log on with API
  5. census_api_key("7a853acf81fd5758228680556ac831138c40b83e")
  6. #load variables
  7. pueblos = 78
  8. variables = load_variables(2020,"acs5/profile")
  9. codes = variables$name
  10. label0 = variables$label
  11. #view variables
  12. #varTable = table(variables$concept)
  13. #write.table(varTable, file = "cat.txt", sep = ",", quote = FALSE, row.names = F)
  14. #pull all tables with every variable
  15. test = get_acs(geography = "county",
  16. state = "PR",
  17. year = tableYear,
  18. variables = codes)
  19. #add label column
  20. #create empty vector
  21. labelCol = c()
  22. #amount of GEOIDS
  23. for (x in 1:pueblos){
  24. labelCol = c(labelCol, label0)
  25. }
  26. #combine test and cols
  27. test["label"] = labelCol
  28. #rearrange cols
  29. test = test[c("NAME","label","variable","estimate","moe","GEOID")]
  30. GEOIDS = table(test$GEOID)
  31. #omit NA rows
  32. noNA = na.omit(test)
  33. DP02table = noNA %>% filter(startsWith(variable,"DP02"))
  34. DP03table = noNA %>% filter(startsWith(variable,"DP03"))
  35. DP04table = noNA %>% filter(startsWith(variable,"DP04"))
  36. DP05table = noNA %>% filter(startsWith(variable,"DP05"))