Subscript a model.matrix object

DESCRIPTION:

This is a method for the function [ 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.

USAGE:

x[j] 
x[i, j] 
x[i, j, drop=<<see below>>] 

REQUIRED ARGUMENTS:

x
An object inheriting from "model.matrix".

OPTIONAL ARGUMENTS:

i, j
subscript expressions
drop
a logical flag controlling whether dimensions of length 0 or 1 are dropped from the return object.

VALUE:

If the column subscript is blank, and more then one row is returned, the result is very similar to 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.

SEE ALSO:

, .

BUGS:

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"))

EXAMPLES:

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