Lab-3

Dr. Elijah Meyer

Duke University
STA 199 - Spring 2023

Feburary 7th, 2023

Checklist

– Go to the course GitHub org and find your lab-03 (repo name will be suffixed with your GitHub name).

– Clone the repo in your container, open the Quarto document in the repo

Announcements

– Labs due Tue (5:00) - Gradescope

– Do not forget to select pages!!

– Look at your code.

  • Did inline code render?

  • Is your code going off the page?

Pivots

pivot_longer

  • cols

  • names_to

  • values_to

pivot_wider

  • names_from

  • values_from

Pivots

– names_transform

Use this argument if you need to change the types of specific columns. For example, names_transform = list(week = as.integer) would convert a character variable called week to an integer.

Full list of arguments: https://tidyr.tidyverse.org/reference/pivot_longer.html

Joins

– R will default to joining data sets together by the same column name. If column names are not the same, there are two options,

  • mutate to make column name the same

  • specify joins using the by argument

Joins

If variable names differ between x and y, use a named character vector like by = c(“x_a” = “y_a”, “x_b” = “y_b”).