O'Reilly logo

Data Manipulation with R - Second Edition by Jaynal Abedin, Kishor Kumar Das

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reshaping the dataset from the typical layout

In this section, we will see how we can convert a typical long layout to a typical wide layout, and vice versa. To perform this conversion, we will use the built-in reshape() function. This takes several arguments, but we will use the following arguments:

  • data: This argument specifies the dataset that we want to change the layout of.
  • direction: This argument specifies whether the data is long or wide. Note that, here, long and wide indicate the typical layout.
  • idvar: This argument specifies the identification variable. It could be a single variable or multiple variables.
  • timevar: This argument specifies how many times the values of idvar repeat for each subject.

The following example converts the students' ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required