Skip to content

Instantly share code, notes, and snippets.

@alexpghayes
Created September 18, 2017 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexpghayes/d3ab64c607ff7145f72297026550c4e2 to your computer and use it in GitHub Desktop.
Save alexpghayes/d3ab64c607ff7145f72297026550c4e2 to your computer and use it in GitHub Desktop.
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