Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(acs)
- api.key.install(key="7876242c28cec9d378629ab9ba095801e0651d07")
- #acs.tables.install()
- zip_geo = geo.make(zip.code = "*")
- ####RACE####
- race.data = acs.fetch(geography=zip_geo, table.number="B03002", col.names = "pretty", endyear = 2015)
- zip_demographics = data.frame(region = as.character(geography(race.data)$zipcodetabulationarea),
- total_population = as.numeric(estimate(race.data[,1])))
- zip_demographics$region = as.character(zip_demographics$region)
- race_df = data.frame(white_alone_not_hispanic = as.numeric(estimate(race.data[,3])),
- black_alone_not_hispanic = as.numeric(estimate(race.data[,4])),
- asian_alone_not_hispanic = as.numeric(estimate(race.data[,6])),
- hispanic_all_races = as.numeric(estimate(race.data[,12])))
- zip_demographics$percent_white = (race_df$white_alone_not_hispanic / zip_demographics$total_population * 100)
- zip_demographics$percent_black = (race_df$black_alone_not_hispanic / zip_demographics$total_population * 100)
- zip_demographics$percent_asian = (race_df$asian_alone_not_hispanic / zip_demographics$total_population * 100)
- zip_demographics$percent_hispanic = (race_df$hispanic_all_races / zip_demographics$total_population * 100)
- #race data table B19013 (columns 1,3,4,6)
- #pop by povert status table B06012 columns 1,2,3,4
- ######POVERTY######
- poverty.data = acs.fetch(geography=zip_geo, table.number="B06012", col.names = "pretty", endyear = 2015)
- poverty.data<-na.omit(poverty.data)
- zip_poverty = data.frame(region = as.character(geography(poverty.data)$zipcodetabulationarea),
- total_population = as.numeric(estimate(poverty.data[,1])))
- zip_poverty<-na.omit(zip_poverty)
- zip_poverty$region = as.character(zip_poverty$region)
- mytable <- results(acs.lookup(endyear=2015, table.number="B06012"))$variable.name
- poverty_df = data.frame(Below_100_percent_of_the_poverty_level = as.numeric(estimate(poverty.data[,2])),
- Hundred_to_149_percent_of_the_poverty_level = as.numeric(estimate(poverty.data[,3])),
- At_or_above_150_percent_of_the_poverty_level = as.numeric(estimate(poverty.data[,4])))
- poverty_df<-na.omit(poverty_df)
- zip_poverty$percent_below100percent= (poverty_df$Below_100_percent_of_the_poverty_level / zip_poverty$total_population * 100)
- zip_poverty$percent_100to149percent = (poverty_df$Hundred_to_149_percent_of_the_poverty_level / zip_poverty$total_population * 100)
- 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