Learn R Programming

umx (version 4.0.0)

umx_stack: Stack data like stack() does, with more control.

Description

Operates like stack(), but can preserve ("passalong") other variables on each row, and allows the user control over the values and group column names for ease of use.

Usage

umx_stack(x, select, passalong, valuesName = "values", groupName = "ind")

Arguments

x

a dataframe containing twin data.

select

The variables to stack (wide 2 long)

passalong

Variables to preserve on each row (e.g. age)

valuesName

The name for the new stacked column (default = "values")

groupName

The name for the column containing the grouping variable (default = "ind")

Value

  • long-format dataframe

See Also

Other Data Functions: umxFactor(), umxHetCor(), umx_as_numeric(), umx_cont_2_quantiles(), umx_lower2full(), umx_make_MR_data(), umx_make_TwinData(), umx_make_fake_data(), umx_make_raw_from_cov(), umx_polychoric(), umx_polypairwise(), umx_polytriowise(), umx_read_lower(), umx_rename(), umx_reorder(), umx_select_valid(), umx

Examples

Run this code
# NOT RUN {
# Base-R stack function
df = stack(mtcars, select = c("disp", "hp"), drop=FALSE)

# umx_stack, with additional variables passed along 
df= umx_stack(mtcars, select= c("disp", "hp"), passalong= "mpg")
str(df) # ind is a factor, with levels select
ggplot2::qplot(x = mpg, y= values, color=ind, data = df)
df= umx_stack(mtcars, select= c("disp", "hp"), passalong= "mpg")
ggplot2::qplot(x = mpg, y= values, group="ind", data = df)
# }

Run the code above in your browser using DataLab