Learn R Programming

iNZightTools (version 1.13.0)

stackVars: Stack variables

Description

Collapse columns by converting from a wide to a long format and returns the result along with tidyverse code used to generate it.

Usage

stackVars(.data, vars, key = "stack.variable", value = "stack.value")

Value

stacked dataframe with tidyverse code attached

Arguments

.data

a dataframe to stack

vars

a character vector of variables to stack

key

name of the new column for the stacked variables. "stack.variable" by default

value

name of the new column for the stacked values of the stacked. "stack.value" by default

Author

Owen Jin

See Also

code

Examples

Run this code
stacked <- stackVars(iris, vars = c("Species", "Sepal.Width"),
    key = "Variable", value = "Value")
cat(code(stacked))
head(stacked)

Run the code above in your browser using DataLab