Skip to content

Joining Data with dplyr

Run the hidden code cell below to import the data used in this course.

# Load the Tidyverse
library(tidyverse)

# Load the course datasets
sets <- read_rds("datasets/sets.rds")
themes <- read_rds("datasets/themes.rds")
parts <- read_rds("datasets/parts.rds")
part_categories <- read_rds("datasets/part_categories.rds")
inventories <- read_rds("datasets/inventories.rds")
inventory_parts <- read_rds("datasets/inventory_parts.rds")
colors <- read_rds("datasets/colors.rds")
questions <- read_rds("datasets/questions.rds")
tags <- read_rds("datasets/tags.rds")
question_tags <- read_rds("datasets/question_tags.rds")
answers <- read_rds("datasets/answers.rds")

Take Notes

Add notes about the concepts you've learned and code cells with code you want to keep.

Add your notes here

Run error
# Start with inventory_parts_joined table
inventory_parts_joined %>%
  # Combine with the sets table 
  inner_join(sets, by = "set_num" %>%
  # Combine with the themes table 
  inner_join(themes, by = c("theme_id" = "id"), suffix = c("_set", "_theme"))
# Add your code snippets here
theme
batman_parts %>%
  # Combine the star_wars_parts table 
  full_join(star_wars_parts, by = c("part_num", "color_id"), suffix = c("_batman", "_star_wars")) %>%
  # Replace NAs with 0s in the n_batman and n_star_wars columns 
  replace_na(list(n_batman = 0, n_star_wars = 0))
parts_joined %>%
  # Sort the number of star wars pieces in descending order 
  arrange(desc(n_star_wars)) %>%
  # Join the colors table to the parts_joined table
  inner_join(colors, by = c("color_id" = "id")) %>%
  # Join the parts table to the previous join 
  inner_join(parts, by = "part_num", suffix = c("_color", "_part"))