Skip to content

Instantly share code, notes, and snippets.

@Yankim Yankim/helpers.R

Last active Sep 19, 2016
What would you like to do?
library(shiny); library(maps); library(mapproj); library(dplyr); library(plotly); library(googleVis); library(car)
#Join data by county indentification numbe (fips) to the county data in the maps package
flipjoin = function(x) {
y = read.csv(x)
left_join(county.fips, y, by = c("fips" = "FIPS"))
#Data wrangling for map plot
health2 = flipjoin("data/health.csv")
socioeconomic2 = flipjoin("data/socioeconomic.csv")
socioeconomic2$POVRATE10 = as.numeric(as.character(socioeconomic2$POVRATE10))
##read data in for non map data
#Data can be found at
socioeconomic = read.csv("data/socioeconomic.csv")
socioeconomic$POVRATE10 = as.numeric(as.character(socioeconomic$POVRATE10))
socioeconomic$MEDHHINC10 = as.numeric(as.character(socioeconomic$MEDHHINC10))
health = read.csv("data/health.csv")
access = read.csv("data/access.csv")
stores = read.csv("data/stores.csv")
restaurants = read.csv("data/restaurants.csv")
insecurity = read.csv("data/insecurity.csv")
local = read.csv("data/local.csv")
#Joining all the datatables together by the FIPS, id number of counties
fulldb = full_join(socioeconomic, health, by = "FIPS") %>%
full_join(., access, by = "FIPS") %>% full_join(., stores, by = "FIPS") %>%
full_join(., restaurants, by = "FIPS") %>% full_join(., insecurity, by = "FIPS") %>%
full_join(., local, by = "FIPS")
#Selecting just the columns of interest.
fulldb = fulldb[, c("FIPS", "State", "County", "PCT_LACCESS_POP10", "GROCPTH12",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.