Data Relations

Objectives

When we analyze data, we often need to combine data from different sources to get the full picture of what’s going on. For example, you might have a spreadsheet that lists students, their years, majors, and demographic information, and another spreadsheet that lists their grade history. How do you combine these tables into a single dataset? This week, we will discuss the family of “join” functions that allow us to combine different datasets. They use the overlap between datasets to smartly join them together so that you have everything in one place. This will make it easier to summarize and visualize your data going forward.

Key concepts

joining functions (left_join, right_join, inner_join, full_join), binding functions (bind_rows), set operations (intersect, union, setdiff), functions for checking your data as you go (glimpse, str, summary)

Readings

You should read this chapter before you come to class:

Slides

Slides have been adapted from the textbook readings using Claude AI.

In-class exercises

We will follow along with the examples given in the textbook. Create an R project called data-relations, and save today’s work in a Quarto report called relations.qmd.

Weekly assignment

Solve the following problems using the concepts you have learned in class. As always, your Quarto report should be organized with headings and comments explaining your work.

  1. Complete the exercise described in the chapter in section 5.11.

  2. Using the completes dataframe that you have created, compute some summary statistics:

    1. What is the mean and standard deviation for the number of points earned on the exam and essay?

    2. Create a table counting how many students earned each grade level for each assessment (e.g., A1, A2, etc).

    3. Now create a table counting how many students earned each grade for each assessment, collapsing across levels within an alphabet grade (e.g., A, B, C).

    4. What proportion of students earned an A on both the exam and the essay?

  3. What is the relationship between students’ grades on the essay and the exam? Use ggplot to create a plot of this relationship.