collapseVar: Collapse a variable in a dataset according to a hierarchy

View source: R/collapseVar.R

collapseVarR Documentation

Collapse a variable in a dataset according to a hierarchy

Description

This function collapses a variable within a dataset based on a given hierarchy. It replaces values in the variable by matching them with elements in the hierarchy. If the variable contains elements not in the hierarchy, a warning is issued.

Usage

collapseVar(data, varname, hierarchy)

Arguments

data

A data frame containing the variable to be collapsed.

varname

The name of the variable to collapse. This can be a character string denoting the variable name or the variable itself.

hierarchy

A numeric vector representing the hierarchy in which to collapse the variable. Values in varname will be replaced according to the order of this hierarchy.

Value

Returns the modified variable as a numeric vector if the collapse is complete. If the collapse is not run due to missing elements in the hierarchy, it returns the original variable.

Examples

## Not run: 
# Assuming 'data' is a data frame and 'hierarchy' is a numeric vector
collapseVar(data = data, varname = "someVar", hierarchy = c(1, 2, 3))

## End(Not run)


Epiconcept-Paris/STRAP-epiuf documentation built on Aug. 5, 2024, 3:41 a.m.