- Start with the
district_idvariable as well as those about number of students by race/ethnicity and get rid of all others (hint: use the
contains()helper function within
pivot_longer()to convert all of the race/ethnicity variables into one variable
pivot_longer(), use the names_to argument to call that variable
pivot_longer(), use the values_to argument to call that variable
The best place to learn more about
pivot_wider() is the pivoting vignette from the
There’s also a nice article by Gavin Simpson of University College, London about pivoting. That article includes the animations below, made by Garrick Aden-Buie and Mara Averick, that gave a visual demonstration of pivoting.
RStudio has a nice primer on reshaping data, complex with a few exercises.
Finally, a heads up: if you ever see references to the functions
spread(), these are the previous iterations of the
pivot functions. They still work (as the tweet below from tidyverse developer Hadley Wickham indicates), but the
pivot functions are, in my view (and the view of many others), much easier to use.