Skip to content

Instantly share code, notes, and snippets.

@andrewbtran
Created March 16, 2017 15:14
Show Gist options
  • Save andrewbtran/5f251dd7fe3634b2c9bd703beac9b5e2 to your computer and use it in GitHub Desktop.
Save andrewbtran/5f251dd7fe3634b2c9bd703beac9b5e2 to your computer and use it in GitHub Desktop.
Generalized code
# Save the dataframe as a consistent name
any_df <- sb
# Rename the first column to "Abbrev"
colnames(any_df)[1] <- "Abbrev"
# Join by the similar name
df_adjusted <- left_join(any_df, pop, by="Abbrev")
# Do the calculations based on the values in the second column
df_adjusted$per_capita <- df_adjusted[,2] / df_adjusted$Population * 100000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment