reshape_long: Reshape a Wide-Form Data Frame to Long-Form

View source: R/reshape_long.R

reshape_longR Documentation

Reshape a Wide-Form Data Frame to Long-Form

Description

A simple wrapper for Base R reshape with sensible parameter names and sensible defaults, and able to specify a range of variables to transform.

Usage

reshape_long(data, transform, group="Group", response="Response", ID="ID",
           prefix=ID, sep="")

Arguments

data

Data frame that contains the variables to reshape.

transform

The wide-form column variable names to transform to a long-form single column.

group

Name of the grouping variable in the new long-form column.

response

Name of the variable of the response values in the new long-form column.

ID

Name of the newly created ID field in the new long-form column, the original row number from the wide-form. If NULL, the default value, then not created.

prefix

The prefix added to the value of ID for each row of data.

sep

Any potential separator of the ID prefix from the given value of the ID.

Details

reshape_long takes the transform variables in the wide-form from which it creates three new columns, group, response, and ID.

The correspondence between the original reshape parameter names and the reshape_long parameter names is shown in the following table.

reshape reshape_long
----------- ----------------
varying transform
v.names response
timevar group
times transform
idvar ID
----------- ----------------

Author(s)

David W. Gerbing (Portland State University; gerbing@pdx.edu)

See Also

reshape.

Examples

d <- Read("Anova_rb")

# with the default variable names in the long-form
reshape_long(d, c("sup1", "sup2", "sup3", "sup4"))

# with a variable range and custom variable names in the long-form
reshape_long(d, sup1:sup4, group="Supplement", response="Reps", ID="Person")

lessR documentation built on Nov. 12, 2023, 1:08 a.m.