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 theidentification
variable. It could be asingle
variable ormultiple
variables.timevar
: This argument specifies how many times the values ofidvar
repeat for each subject.
The following example converts the students' data that was created earlier from a long layout to a wide layout:
# Reshaping dataset using reshape function wide_students <- reshape(students,direction="wide",idvar="sid",timevar="exmterm") wide_students sid math.1 literature.1 language.1...