[
for objects inheriting from
class
model.matrix
. See
[
for the general behavior of this function.
This function differs in returning a
model.matrix
when the default
version would return a matrix.
x[j] x[i, j] x[i, j, drop=<<see below>>]
"model.matrix"
.
x
-- key attributes are unchanged.
If columns are subscripted, and the result is a matrix, then it is also
a
"model.matrix"
. This shouldnt really
be a
"model.matrix"
, because we dont know if this could have been
created by then
function, but this is done for backward compatibility.
Some attributes are omitted, but this may change in future versions.
Explicitly seting
drop=TRUE
, rather than leaving it blank, forces
the second version with some attributes omitted.
If the object is of a class that inherits from
"model.matrix"
but is
not itself a
"model.matrix"
object, then you must copy the S4 method
for
"model.matrix"
to your new class for the
"model.matrix"
subscripting
to be used:
setMethod("[", "myclass", getMethod("[", "model.matrix"))
x <- model.matrix(Fuel~., data = fuel.frame) x[1:5,] # model matrix, with key attributes unchanged x[,1:2] # model matrix, with some attributes changed x[1,] # vector x[,1] # vector