No Description

R.R 806B

12345678910111213141516171819202122232425262728293031323334353637
  1. library(tidycensus)
  2. library(tidyverse)
  3. #log on with API
  4. census_api_key("7a853acf81fd5758228680556ac831138c40b83e")
  5. callData = function(year,table,municipality) {
  6. #year is between 2000 and 2020
  7. #table is dp02pr, dp03, dp04, dp05
  8. #load variables
  9. variables = load_variables(year,"acs5/profile")
  10. #load variable vectors
  11. codes = variables$name
  12. codesBool = startsWith(codes,table)
  13. codes = codes[codesBool]
  14. labels = variables$label[codesBool]
  15. #pull table
  16. bigTable = get_acs(geography = "county",
  17. state = "PR",
  18. year = year,
  19. county = municipality,
  20. variables = codes)
  21. bigTable$Label = labels
  22. bigTable = bigTable[c("Label","estimate","moe")]
  23. return(bigTable)
  24. }
  25. table = callData(2020,"DP05","Aguada")