matrix {base} | R Documentation |
matrix
creates a matrix from the given set of values.
as.matrix
attempts to turn its argument into a matrix.
is.matrix
tests if its argument is a (strict) matrix.
It is generic: you can write methods to handle
of specific classes of objects, see InternalMethods.
matrix(data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL) as.matrix(x) is.matrix(x)
data |
an optional data vector. |
nrow |
the desired number of rows |
ncol |
the desired number of columns |
byrow |
logical. If FALSE
(the default) the matrix is filled by columns, otherwise the matrix is
filled by rows. |
dimnames |
A dimnames attribute for the matrix: a
list of length 2. |
x |
an R object. |
If either of nrow
or ncol
is not given, an attempt is
made to infer it from the length of data
and the other
parameter.
is.matrix
returns TRUE
if x
is a matrix (i.e., it
is not a data.frame
and has a dim
attribute of length 2) and FALSE
otherwise.
as.matrix
is a generic function. The method for data frames
will convert any non-numeric column into a character vector using
format
and so return a character matrix.
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
data.matrix
, which attempts to convert to a numeric matrix.
is.matrix(as.matrix(1:10)) data(warpbreaks) !is.matrix(warpbreaks)# data.frame, NOT matrix! str(warpbreaks) str(as.matrix(warpbreaks))#using as.matrix.data.frame(.) method