Created
September 18, 2017 01:09
-
-
Save alexpghayes/d3ab64c607ff7145f72297026550c4e2 to your computer and use it in GitHub Desktop.
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(tidyverse) | |
beans <- c("Caturra", "Grusti", "Double roasted") | |
coffees <- c("Garuda", "Blend 101", "Blend 201", "Exxxtra special blend") | |
location <- c("Rwanda", "Columbia", "Peru") | |
people <- c("Dan Wallach", "Chris Jermaine", "Scott Rikner", "Luay") | |
has_bean <- tibble( | |
coffee = sample(coffees, 10, replace = TRUE), | |
bean_name = sample(beans, 10, replace = TRUE) | |
) %>% | |
distinct() | |
drinks <- tibble( | |
name = sample(people, 15, replace = TRUE), | |
coffee = sample(coffees, 15, replace = TRUE) | |
) %>% | |
distinct() | |
bean <- tibble( | |
bean_name = sample(beans, 20, replace = TRUE), | |
from_location = sample(location, 20, replace = TRUE) | |
) %>% | |
distinct() | |
has_bean | |
drinks | |
bean | |
# code: relational algebraic equivalencies | |
# these are all from the `dplyr` library | |
# left_join: natural_join | |
# filter: (select/sigma operator) | |
# select: (project/pi operator) | |
# %>%: forward pipe operator, use to chain together operations | |
# you may also interested in the anti_join operator, as well as group_by, | |
# mutate, and summarize | |
# an example: all coffees with beans from Peru | |
bean %>% | |
left_join(has_bean) %>% | |
filter(from_location == "Peru") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment