Learn R Programming

crunch (version 1.30.4)

flipArrays: Rearrange array subvariables

Description

Sometimes it is useful to group subvariables across arrays in order to compare them more easily. This function generates a set of derived views of common subvariables across arrays. Because they are derived, they share data with the underlying array variables, and they are thus automatically updated when new data is appended.

Usage

flipArrays(variables, suffix = ", flipped")

Value

A list of derived VariableDefinitions, one per unique subvariable name across all variables. Each variable in variables that contains this subvariable will appear as a subvariable in these new derived array definitions. Use addVariables to add these to your dataset.

Arguments

variables

List of variables, a variable catalog, or a dataset subset containing the categorical array or multiple response variables you want to rearrange.

suffix

character string to append to the new variable names. Pass "" if you don't want it to append anything.

Examples

Run this code
if (FALSE) {
ds <- addVariables(ds, flipArrays(ds[c("petloc", "petloc2")], suffix = ", rearranged"))
}

Run the code above in your browser using DataLab