Compute possibly sparse model matrix
model_matrix(
formula,
data = environment(formula),
contrasts.arg = NULL,
drop.unused.levels = FALSE,
sparse = NULL,
drop0 = TRUE,
catsep = "",
by = NULL,
tabM = FALSE
)
model formula.
data frame containing all variables used in formula
.
These variables should not contain missing values. An error is raised in case any of them does.
specification of contrasts for factor variables. Currently supported are "contr.none" (no contrasts applied), "contr.treatment" (first level removed) and "contr.SAS" (last level removed). Alternatively, a named list specifying a single level per factor variable can be passed.
whether empty levels of individual factor variables should be removed.
if TRUE
a sparse matrix of class dgCMatrix
is returned. This can be efficient
for large datasets and a model containing categorical variables with many categories. If sparse=NULL
, the default,
whether a sparse or dense model matrix is returned is based on a simple heuristic.
whether to drop any remaining explicit zeros in resulting sparse matrix.
separator for concatenating factor variable names and level names.
By default it is the empty string, reproducing the labels of model.matrix
.
a vector by which to aggregate the result.
if TRUE
return a list of tabMatrix objects.
Design matrix X, either an ordinary matrix or a sparse dgCMatrix
.