collapseVar | R Documentation |
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.
collapseVar(data, varname, hierarchy)
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 |
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.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.