43 lines
1.2 KiB
R
43 lines
1.2 KiB
R
library(tidyverse)
|
|
library(tidycensus)
|
|
library(zipcodeR)
|
|
install.packages("zipcodeR")
|
|
install.packages("units")
|
|
|
|
|
|
#install.packages("terra")
|
|
census_api_key(KEY, install = TRUE)
|
|
KEY <- '30e13ab22563318ff59286e433099f4174d4edd4'
|
|
#Ex
|
|
TRACTS <-get_tracts(search_city('Kemmerer','WY')$zipcode) %>% full_join(get_tracts(search_city('Diamondville','WY')$zipcode))
|
|
get_decennial(geography="tract",variables=vars,state='WY',county='lincoln')
|
|
|
|
c('B01002_001E','B01002_002E','B01002_003E')
|
|
c('Median_Age','Median_Age_Male','Median_Age_Female')
|
|
|
|
|
|
|
|
|
|
|
|
get_acs(geography="tract",variables=vars,state='WY',county='lincoln',GEOID='56023978400')
|
|
######MALE
|
|
|
|
#Variable names from: https://api.census.gov/data/2019/acs/acs1/variables.html
|
|
sapply(1:25,function(x){paste0("B01001_00",x,"E")})
|
|
c(seq(0,15,by=5),18,20,21,22,seq(25,85,by=5))
|
|
c(seq(4,17,by=5),17,19,20,21,24,seq(29,84,by=5))
|
|
CODES <- read_csv("Data/API_CENSUS_CODES.csv") %>% mutate(Med_Age=(Min_Age+Max_Age)/2)
|
|
VARS <- CODES$Code
|
|
|
|
#Testing age Comparison between the two
|
|
TEMP <- get_acs(geography="tract",variables=VARS,state='WY',county='lincoln')
|
|
KEM <- TEMP %>% filter(GEOID=='56023978400')
|
|
KEM
|
|
19/sum(KEM$estimate)
|
|
|
|
LN <- TEMP %>% filter(GEOID!='56023978400')
|
|
LN
|
|
19/sum(KEM$estimate)
|
|
|
|
|