Skip to content

Instantly share code, notes, and snippets.

@andrewbtran
Created March 16, 2017 15:33
Show Gist options
  • Save andrewbtran/d7f0652dc870d3ab7c50786aaeb24cc3 to your computer and use it in GitHub Desktop.
Save andrewbtran/d7f0652dc870d3ab7c50786aaeb24cc3 to your computer and use it in GitHub Desktop.
new function
pc_adjust <- function(any_df, state_type){
# bring in the population lookup table
pop <- read.csv("https://docs.google.com/spreadsheets/d/16oW_uvRJCNoOnCeAkJH4fDouFokjaGUdGFUCaFdKd6I/pub?output=csv", stringsAsFactors=F)
# State type options are either "Abbrev" or "State"
colnames(any_df)[1] <- state_type
df_adjusted <- left_join(any_df, pop, by=state_type)
df_adjusted$per_capita <- df_adjusted[,2] / df_adjusted$Population * 1000000
return(df_adjusted)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment