wide2long | R Documentation |
Converts wide-format data to long-format data.
wide2long(x, y = NULL, grpnames=NULL)
x |
A data frame or matrix containing two columns for the observations in groups. |
y |
Optional; a vector containing data to combine with |
grpnames |
Optional character string vector for the names of groups, e.g. c("A","B"). |
This function converts wide-format data to long format by combining two columns of data into a single column and creating a grouping variable to distinguish the original data sources.
A data frame with two columns: Obs
containing the combined values of x
and y
, and group
indicating the original data source.
Zeynel Cebeci, A. Firat Ozdemir, Engin Yildiztepe
long2wide
# Normal distributed groups of data with equal means and different variances
set.seed(2)
grp1 <- rnorm(20, 50, 5)
grp2 <- rnorm(20, 50, 9)
ds1 <- data.frame(A=grp1, B=grp2)
head(ds1)
bivarplot(ds1)
# Convert to long data
ds2 <- wide2long(ds1)
head(ds2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.