Import Data
childcare_costs <- read.csv('childcare_costs.csv')
counties <- read.csv('counties.csv')
Make data small
set.seed(1234)
childcare_small <- childcare_costs %>%
select(county_fips_code, study_year, mcsa, mfccsa) %>%
na.omit(TRUE) %>%
sample_n(10)
childcare_small
## county_fips_code study_year mcsa mfccsa
## 1 22119 2009 90.00 83.72
## 2 26021 2008 119.80 92.64
## 3 22053 2016 128.00 75.00
## 4 26033 2012 116.07 92.85
## 5 27069 2011 135.00 100.00
## 6 1113 2014 83.42 102.82
## 7 45061 2015 100.00 70.00
## 8 32007 2012 114.61 116.61
## 9 5007 2015 100.00 85.00
## 10 39093 2012 114.01 107.48
counties_small <- counties %>%
select(county_fips_code, county_name, state_abbreviation) %>%
sample_n(10)
counties_small
## county_fips_code county_name state_abbreviation
## 1 51770 Roanoke city VA
## 2 40027 Cleveland County OK
## 3 48499 Wood County TX
## 4 30053 Lincoln County MT
## 5 46023 Charles Mix County SD
## 6 21217 Taylor County KY
## 7 51650 Hampton city VA
## 8 8047 Gilpin County CO
## 9 41045 Malheur County OR
## 10 48195 Hansford County TX
Inner Join
childcare_small %>% inner_join(counties, by = c("county_fips_code"))
## county_fips_code study_year mcsa mfccsa county_name
## 1 22119 2009 90.00 83.72 Webster Parish
## 2 26021 2008 119.80 92.64 Berrien County
## 3 22053 2016 128.00 75.00 Jefferson Davis Parish
## 4 26033 2012 116.07 92.85 Chippewa County
## 5 27069 2011 135.00 100.00 Kittson County
## 6 1113 2014 83.42 102.82 Russell County
## 7 45061 2015 100.00 70.00 Lee County
## 8 32007 2012 114.61 116.61 Elko County
## 9 5007 2015 100.00 85.00 Benton County
## 10 39093 2012 114.01 107.48 Lorain County
## state_name state_abbreviation
## 1 Louisiana LA
## 2 Michigan MI
## 3 Louisiana LA
## 4 Michigan MI
## 5 Minnesota MN
## 6 Alabama AL
## 7 South Carolina SC
## 8 Nevada NV
## 9 Arkansas AR
## 10 Ohio OH
Left Join
childcare_small %>% left_join(counties, by = c("county_fips_code"))
## county_fips_code study_year mcsa mfccsa county_name
## 1 22119 2009 90.00 83.72 Webster Parish
## 2 26021 2008 119.80 92.64 Berrien County
## 3 22053 2016 128.00 75.00 Jefferson Davis Parish
## 4 26033 2012 116.07 92.85 Chippewa County
## 5 27069 2011 135.00 100.00 Kittson County
## 6 1113 2014 83.42 102.82 Russell County
## 7 45061 2015 100.00 70.00 Lee County
## 8 32007 2012 114.61 116.61 Elko County
## 9 5007 2015 100.00 85.00 Benton County
## 10 39093 2012 114.01 107.48 Lorain County
## state_name state_abbreviation
## 1 Louisiana LA
## 2 Michigan MI
## 3 Louisiana LA
## 4 Michigan MI
## 5 Minnesota MN
## 6 Alabama AL
## 7 South Carolina SC
## 8 Nevada NV
## 9 Arkansas AR
## 10 Ohio OH
Right Join
childcare_small %>% right_join(counties, by = c("county_fips_code")) %>%
sample_n(10)
## county_fips_code study_year mcsa mfccsa county_name state_name
## 1 39011 NA NA NA Auglaize County Ohio
## 2 31053 NA NA NA Dodge County Nebraska
## 3 48151 NA NA NA Fisher County Texas
## 4 25023 NA NA NA Plymouth County Massachusetts
## 5 54011 NA NA NA Cabell County West Virginia
## 6 24039 NA NA NA Somerset County Maryland
## 7 20197 NA NA NA Wabaunsee County Kansas
## 8 13167 NA NA NA Johnson County Georgia
## 9 17059 NA NA NA Gallatin County Illinois
## 10 20007 NA NA NA Barber County Kansas
## state_abbreviation
## 1 OH
## 2 NE
## 3 TX
## 4 MA
## 5 WV
## 6 MD
## 7 KS
## 8 GA
## 9 IL
## 10 KS
Full Join
childcare_small %>% full_join(counties, by = c("county_fips_code")) %>%
sample_n(10)
## county_fips_code study_year mcsa mfccsa county_name state_name
## 1 16035 NA NA NA Clearwater County Idaho
## 2 27169 NA NA NA Winona County Minnesota
## 3 22019 NA NA NA Calcasieu Parish Louisiana
## 4 5021 NA NA NA Clay County Arkansas
## 5 55125 NA NA NA Vilas County Wisconsin
## 6 21023 NA NA NA Bracken County Kentucky
## 7 18067 NA NA NA Howard County Indiana
## 8 37117 NA NA NA Martin County North Carolina
## 9 8087 NA NA NA Morgan County Colorado
## 10 36007 NA NA NA Broome County New York
## state_abbreviation
## 1 ID
## 2 MN
## 3 LA
## 4 AR
## 5 WI
## 6 KY
## 7 IN
## 8 NC
## 9 CO
## 10 NY
Semi Join
childcare_small %>% semi_join(counties, by = c("county_fips_code"))
## county_fips_code study_year mcsa mfccsa
## 1 22119 2009 90.00 83.72
## 2 26021 2008 119.80 92.64
## 3 22053 2016 128.00 75.00
## 4 26033 2012 116.07 92.85
## 5 27069 2011 135.00 100.00
## 6 1113 2014 83.42 102.82
## 7 45061 2015 100.00 70.00
## 8 32007 2012 114.61 116.61
## 9 5007 2015 100.00 85.00
## 10 39093 2012 114.01 107.48
Anti Join
childcare_small %>% anti_join(counties, by = c("county_fips_code"))
## [1] county_fips_code study_year mcsa mfccsa
## <0 rows> (or 0-length row.names)