Created
March 16, 2017 15:33
-
-
Save andrewbtran/d7f0652dc870d3ab7c50786aaeb24cc3 to your computer and use it in GitHub Desktop.
new function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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