Last active
June 19, 2019 17:58
-
-
Save josephsdavid/2ecf2c94ad4e0bb6c3cffb48e9f93de8 to your computer and use it in GitHub Desktop.
beer
This file contains 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
library(dplyr) # so we can use %>% pipes! | |
rawBeer <- read.csv(file = "../data/raw/Beers.csv",header=TRUE, sep=",",stringsAsFactors=FALSE) | |
rawBrew <- read.csv(file= "../data/raw/Breweries.csv", header=TRUE, sep=",", stringsAsFactors=FALSE) | |
head(rawBeer) | |
# Name Beer_ID ABV IBU Brewery_id Style | |
# 1 Pub Beer 1436 0.050 NA 409 American Pale Lager | |
# 2 Devil's Cup 2265 0.066 NA 178 American Pale Ale (APA) | |
# 3 Rise of the Phoenix 2264 0.071 NA 178 American IPA | |
# 4 Sinister 2263 0.090 NA 178 American Double / Imperial IPA | |
# 5 Sex and Candy 2262 0.075 NA 178 American IPA | |
# 6 Black Exodus 2261 0.077 NA 178 Oatmeal Stout | |
# Ounces | |
# 1 12 | |
# 2 12 | |
# 3 12 | |
# 4 12 | |
# 5 12 | |
# 6 12 | |
head(rawBrew) | |
# Brew_ID Name City State | |
# 1 1 NorthGate Brewing Minneapolis MN | |
# 2 2 Against the Grain Brewery Louisville KY | |
# 3 3 Jack's Abby Craft Lagers Framingham MA | |
# 4 4 Mike Hess Brewing Company San Diego CA | |
# 5 5 Fort Point Beer Company San Francisco CA | |
# 6 6 COAST Brewing Company Charleston SC | |
rawBeer %>% rename(Brewery_ID=Brewery_id) -> Beer1 | |
rawBrew %>% rename(Brewery_ID=Brew_ID) -> Brew1 | |
Beer1 %>% select(Name,Beer_ID,ABV,IBU,Style,Ounces,Brewery_ID) -> Beer1 | |
BeerBrew <- merge(Beer1,Brew1, by='Brewery_ID') | |
BeerBrew %>% rename(BeerName = Name.x) %>% rename(BreweryName = Name.y) -> BeerBrew | |
BeerBrew %>% select(BeerName,Beer_ID,ABV,IBU,Style,Ounces,BreweryName,Brewery_ID,City,State) -> BeerBrew | |
head(BeerBrew) | |
# BeerName Beer_ID ABV IBU Style Ounces BreweryName Brewery_ID City State | |
# 1 Get Together 2692 0.045 50 American IPA 16 NorthGate Brewing 1 Minneapolis MN | |
# 2 Maggie's Leap 2691 0.049 26 Milk / Sweet Stout 16 NorthGate Brewing 1 Minneapolis MN | |
# 3 Wall's End 2690 0.048 19 English Brown Ale 16 NorthGate Brewing 1 Minneapolis MN | |
# 4 Pumpion 2689 0.060 38 Pumpkin Ale 16 NorthGate Brewing 1 Minneapolis MN | |
# 5 Stronghold 2688 0.060 25 American Porter 16 NorthGate Brewing 1 Minneapolis MN | |
# 6 Parapet ESB 2687 0.056 47 Extra Special / Strong Bitter (ESB) 16 NorthGate Brewing 1 Minneapolis MN | |
data.frame(sapply(BeerBrew, function(y) sum(length(which(is.na(y)))))) %>% rename(na_count=sapply.BeerBrew..function.y..sum.length.which.is.na.y.....) | |
# na_count | |
# BeerName 0 | |
# Beer_ID 0 | |
# ABV 62 | |
# IBU 1005 | |
# Style 0 | |
# Ounces 0 | |
# BreweryName 0 | |
# Brewery_ID 0 | |
# City 0 | |
# State 0 | |
StateSummary <- BeerBrew %>% | |
group_by(State) %>% | |
summarise(medianABV = median(ABV, na.rm=TRUE), | |
medianIBU = median(IBU, na.rm=TRUE), | |
NumBreweries = n_distinct(Brewery_ID)) %>% | |
data.frame | |
# State medianABV medianIBU NumBreweries | |
# 1 AK 0.0560 46.0 7 | |
# 2 AL 0.0600 43.0 3 | |
# 3 AR 0.0520 39.0 2 | |
# 4 AZ 0.0550 20.5 11 | |
# 5 CA 0.0580 42.0 39 | |
# 6 CO 0.0605 40.0 47 | |
MaxABV <- BeerBrew %>% | |
select(State, BeerName, ABV) %>% | |
filter(!is.na(ABV)) %>% | |
top_n(ABV,n=1) | |
# State BeerName ABV | |
# 1 CO Lee Hill Series Vol. 5 - Belgian Style Quadrupel Ale 0.128 | |
MaxIBU <- BeerBrew %>% | |
select(State, BeerName, IBU) %>% | |
filter(!is.na(IBU)) %>% | |
arrange(desc(IBU)) %>% | |
slice(1) | |
# State BeerName IBU | |
# 1 OR Bitter Bitch Imperial IPA 138 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment