Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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

Examples

# 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)

umx

Structural Equation Modeling and Twin Modeling in R

v4.10.10
GPL-3
Authors
Timothy C. Bates [aut, cre] (<https://orcid.org/0000-0002-1153-9007>), Gillespie Nathan [wit], Michael Zakharin [wit], Brenton Wiernik [ctb], Joshua N. Pritikin [ctb], Michael C. Neale [ctb], Hermine Maes [ctb]
Initial release
2021-11-30

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.