Guest User

Untitled

a guest
Jun 18th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. library(acs)
  2.  
  3. api.key.install(key="7876242c28cec9d378629ab9ba095801e0651d07")
  4.  
  5. #acs.tables.install()
  6.  
  7. zip_geo = geo.make(zip.code = "*")
  8.  
  9. ####RACE####
  10.  
  11. race.data = acs.fetch(geography=zip_geo, table.number="B03002", col.names = "pretty", endyear = 2015)
  12.  
  13. zip_demographics = data.frame(region = as.character(geography(race.data)$zipcodetabulationarea),
  14. total_population = as.numeric(estimate(race.data[,1])))
  15.  
  16. zip_demographics$region = as.character(zip_demographics$region)
  17.  
  18. race_df = data.frame(white_alone_not_hispanic = as.numeric(estimate(race.data[,3])),
  19. black_alone_not_hispanic = as.numeric(estimate(race.data[,4])),
  20. asian_alone_not_hispanic = as.numeric(estimate(race.data[,6])),
  21. hispanic_all_races = as.numeric(estimate(race.data[,12])))
  22.  
  23. zip_demographics$percent_white = (race_df$white_alone_not_hispanic / zip_demographics$total_population * 100)
  24. zip_demographics$percent_black = (race_df$black_alone_not_hispanic / zip_demographics$total_population * 100)
  25. zip_demographics$percent_asian = (race_df$asian_alone_not_hispanic / zip_demographics$total_population * 100)
  26. zip_demographics$percent_hispanic = (race_df$hispanic_all_races / zip_demographics$total_population * 100)
  27.  
  28. #race data table B19013 (columns 1,3,4,6)
  29. #pop by povert status table B06012 columns 1,2,3,4
  30.  
  31. ######POVERTY######
  32.  
  33. poverty.data = acs.fetch(geography=zip_geo, table.number="B06012", col.names = "pretty", endyear = 2015)
  34. poverty.data<-na.omit(poverty.data)
  35.  
  36. zip_poverty = data.frame(region = as.character(geography(poverty.data)$zipcodetabulationarea),
  37. total_population = as.numeric(estimate(poverty.data[,1])))
  38. zip_poverty<-na.omit(zip_poverty)
  39.  
  40. zip_poverty$region = as.character(zip_poverty$region)
  41.  
  42. mytable <- results(acs.lookup(endyear=2015, table.number="B06012"))$variable.name
  43.  
  44. poverty_df = data.frame(Below_100_percent_of_the_poverty_level = as.numeric(estimate(poverty.data[,2])),
  45. Hundred_to_149_percent_of_the_poverty_level = as.numeric(estimate(poverty.data[,3])),
  46. At_or_above_150_percent_of_the_poverty_level = as.numeric(estimate(poverty.data[,4])))
  47. poverty_df<-na.omit(poverty_df)
  48.  
  49. zip_poverty$percent_below100percent= (poverty_df$Below_100_percent_of_the_poverty_level / zip_poverty$total_population * 100)
  50. zip_poverty$percent_100to149percent = (poverty_df$Hundred_to_149_percent_of_the_poverty_level / zip_poverty$total_population * 100)
  51. zip_poverty$percent_above149percent= (poverty_df$At_or_above_150_percent_of_the_poverty_level / zip_poverty$total_population * 100)
Add Comment
Please, Sign In to add comment