tidyr::pivot_longer()
to reshape from wider-to-longer formatpivot_longer()
looks like this:tidyr::pivot_longer()
to gather data from all years in inverts (columns 2016
, 2017
, and 2018
) into two columns:dplyr::mutate()
in a different way here: to create a new column (that’s how we’ve used mutate()
previously) that has the same name of an existing column, in order to update and overwrite the existing column.mutate()
to add a column called year, which contains an as.numeric()
version of the existing year variable: