설명 없음

R.R 1.1KB

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