reshape_wide: Reshape a Wide-Form Data Frame to Wide-Form

View source: R/reshape_wide.R

reshape_wideR Documentation

Reshape a Wide-Form Data Frame to Wide-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_wide(data, group, response, ID, prefix=NULL, sep="_")

Arguments

data

Data frame that contains the variables to analyze wide-form single column.

group

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

response

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

ID

Name of the ID field in the long-form column.

prefix

If TRUE, prefix the column names in the wide form of each corresponding level of the group variable with the name of the response. Unless the values of group are numeric, the default is FALSE, just using the level names as the column names.

sep

If prefix is TRUE, the separator between the name of the level and the name of the response variable, with default "_".

Details

reshape_wide takes the variables in the long-form group, response, and ID and transforms to wide form.

Here is the correspondence between the original reshape parameter names and the reshape_wide parameter names.

reshape reshape_wide
----------- ----------------
v.names response
timevar group
idvar ID
----------- ----------------

Author(s)

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

See Also

reshape.

Examples

d <- Read("Anova_rb")  # already in wide-form
dl <- reshape_long(d, sup1:sup4)  # convert to long-form

# convert back to wide form 
reshape_wide(dl, group="Group", response="Response", ID="Person")

# with the name of the response prefixed to the column names
reshape_wide(dl, group="Group", response="Response", ID="Person",
             prefix=TRUE, sep=".")

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