R pivot_wide

  • pivot_wider() “widens” data, increasing the number of columns and decreasing the number of rows. 
  • Transforms data from long format to wide format.
  • Makes multiple columns into key-value pairs, creating a shorter, wider dataset.
  • Part of the tidyr package, which is included in the tidyverse.


Key Arguments:

  1. data: The data frame to be reshaped.
  2. names_from: The column containing the names for the new wide columns.
  3. values_from: The column containing the values to be spread across the wide columns

Example: Below, we are using the madeup data and converting it to a wider table

Go here to see how converted this table back to longer table

Example 2: Let us convert this table below to a wide version on the using the models in the trans

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top