Created
March 16, 2017 16:13
-
-
Save andrewbtran/36cf667643d7be413bba6834d9a73da8 to your computer and use it in GitHub Desktop.
metadata
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
#' Population adjuster | |
#' | |
#' This function appends state population data | |
#' @param any_df The name of the dataframe you want to append to | |
#' @param state_type if state identification is abbreviations, use "Abbrev" if full state name, use "State" | |
#' @keywords per capita | |
#' @import dplyr | |
#' @export | |
#' @examples | |
#' pc_adjust(dataframe, "Abbrev") | |
pc_adjust <- function(any_df, state_type){ | |
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