reshape_wide {lessR} | R Documentation |
Reshape a Long-Form Data Frame to Wide-Form
Description
Takes the variables in a long-form data frame, widen
, response
, and ID
, and transforms to a wide form data frame. All other variables are deleted in the transformed data frame. A simple wrapper for Base R reshape
with sensible parameter names and sensible defaults, and able to specify a range of variables to transform. Conversion currently limited to converting based on a single grouping variable.
Usage
reshape_wide(data, widen, response, ID, prefix=NULL, sep="_", ...)
Arguments
data |
Data frame that contains the variables to analyze as a wide-form single column. |
widen |
Name of the (single) grouping variable in the input long-form column to have its individual values listed as columns in the corresponding wide form version. |
response |
Name of the variable of the response values in the input long-form column that becomes the data values in the wide-form version. |
ID |
Name of the ID field in the long-form column used to identify each row in the wide-form version. |
prefix |
If |
sep |
If |
... |
Older parameter values to be converted internally. |
Details
Here is the correspondence between the original reshape
parameter names and the reshape_wide
parameter names.
reshape | reshape_wide |
----------- | ---------------- |
v.names | response |
timevar | widen |
idvar | ID |
----------- | ---------------- |
Author(s)
David W. Gerbing (Portland State University; gerbing@pdx.edu)
See Also
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, widen=Group, response=Response, ID=Person)
# with the name of the response prefixed to the column names
reshape_wide(dl, widen=Group, response=Response, ID=Person,
prefix=TRUE, sep=".")