Reshaping data in R to be long or wide with pivot_longer and pivot_wider (CC185)
R’s tidyverse tidyr package has powerful functions for reshaping data frames to be long or wide using the pivot_longer
and pivot_wider
functions, respectively. In this episode, Pat Schloss will show how to use these functions to convert a distance matrix into a format that is easier to use with other tools like inner_join
and filter
. The goal of this episode is to filter a square distance matrix to only contain distances from a subset of samples. We’ll do all this in RStudio using the tidyverse package.
Code
You can browse the state of the repository at the