If one of
ncol is not given, an attempt is
made to infer it from the length of
data and the other
parameter. If neither is given, a one-column matrix is returned.
If there are too few elements in
data to fill the matrix,
then the elements in
data are recycled. If
NA of an appropriate type is used for atomic
0 for raw vectors) and
NULL for lists.
x is a vector and has a
"dim" attribute of length 2 and
Note that a
data.frame is not a matrix by this
test. The function is generic: you can write methods to handle
specific classes of objects, see InternalMethods.
as.matrix is a generic function. The method for data frames
will return a character matrix if there is only atomic columns and any
non-(numeric/logical/complex) column, applying
to factors and
format to other non-character columns.
Otherwise, the usual coercion hierarchy (logical < integer < double <
complex) will be used, e.g., all-logical data frames will be coerced
to a logical matrix, mixed logical-integer will give a integer matrix,
The default method for
hence e.g.coerces factors to character vectors.
When coercing a vector, it produces a one-column matrix, and
promotes the names (if any) of the vector to the rownames of the matrix.
is.matrix is a primitive function.
print method for a matrix gives a rectangular layout with
dimnames or indices. For a list matrix, the entries of length not
one are printed in the form integer,7 indicating the type