View source: R/data_manip_utils.R
strip_design_factor_names | R Documentation |
The standard model.matrix()
function generates column names for
factor columns by concatenating the factor's name with the level.
This helps guarantee non-duplicated column names in the general
case, but for simple cases it results in overly long and complex
column names. This function removes the factor names, leaving only
the level names.
strip_design_factor_names(design, prefixes = names(attr(design, "contrasts")))
design |
The design matrix whose column names should be
cleaned up (usually created by |
prefixes |
A character vector of prefixes to be deleted from
column names. Normally, this argument is set automatically
based on the attributes of |
The same matrix as design
, possibly with some column
names shortened by deleting one of prefixes
from the start of
the column names.
Column names for columns not corresponding to factors are left unchanged.
Note that this is only guaranteed to work correctly if none of your variable names are prefixes of other variable names.
A warning will be issued if, after stripping factor names, the
column names of design
are no longer unique.
targets <- data.frame(group = letters[1:2], batch = LETTERS[1:5], x = rnorm(10)) design <- model.matrix(~0 + group + x + batch, targets) colnames(design) design2 <- strip_design_factor_names(design) colnames(design2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.