model.matrix {base} | R Documentation |
Creates a design matrix from the description given in
terms(formula)
, using the data in data
which must
contain columns with the same names as would be created by a call to
model.frame(formula)
or, more precisely, by evaluating
attr(terms(formula), "variables")
. There may be other columns
and the order is not important.
model.matrix(formula =, data =)
formula |
A model formula or terms object |
data |
A data frame created with |
The design matrix for a regression model with the specified formula and data.
Chambers and Hastie: "Statistical Models in S"
model.frame
, model.data.frame
,
terms
data(trees)
ff <- log(Volume) ~ log(Height) + log(Girth)
m <- model.frame(ff, trees)
mat <- model.matrix(ff, m)