matrix(data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL) is.matrix(x) as.matrix(x, ...) ## S3 method for class 'data.frame': as.matrix(x, rownames.force = NA, ...) ## S3 method for class 'POSIXlt': as.matrix(x, ...)
x | any object. |
data | a vector containing the data values for the matrix. Missing values (NAs) are allowed. |
nrow | the first subscript: the number of rows. The default is ceiling(length(data)/ncol). That is, if ncol is specified, nrow is chosen to match the length of data. If neither nrow nor ncol are specified, then nrow is the length of data and ncol is 1. |
ncol | the second subscript: the number of columns. If nrow is specified but ncol is not, then ncol is defined as ceiling(length(data)/nrow). |
byrow | a logical flag. If TRUE, the data values are assumed to be the first row, then the second row, and so on. If FALSE (the default), the values are assumed to be the first column, then the second column, and so on. (The latter is how the data are stored internally.) |
dimnames | a list of length 2 giving a dimnames attribute for the matrix. Each component must either have length 0 or be a vector of character strings with length equal to the corresponding element of the dim attribute of the result. |
rownames.force | any object. when rownames.force is a logical value, if TRUE, matrix row names must be generated from the data frame; if FALSE, the rownames attribute is NULL, regardless if the data frame has row names. The default NA or any other values, indicate that if the data frame has no specified row names, the rownames attribute is NULL; but if the data frame has row names, these become the row names of the returned matrix. |
... | additional arguments to be passed to or from methods. |
matrix | returns an nrow by ncol matrix with the same mode as data. If the data does not fill the matrix, it is repeated until the matrix is filled. |
is.matrix | returns TRUE if dim(x) is of length 2; otherwise, it returns FALSE. |
as.matrix | returns x, if x is a matrix.
|
as.matrix.data.frame | TIBCO Enterprise Runtime for R always returns a matrix with the row names attributes set. and is not compatible with R in this regard, as R returns a matrix with no row names set if the source data frame has "default" row names. |
m <- matrix(0, 4, 5) # a 4 by 5 matrix of zeros is.matrix(m) # TRUEmatrix(1:10, 5) # a 5 by 2 matrix matrix(1:10, ncol=2) # the same thing matrix(1:10, ncol=2, byrow=TRUE) # row-major order t(matrix(1:10, nrow=2)) # the same thing
as.matrix(1:3) # as.matrix for a vector df <- data.frame(a = c(1:3), b = c("R", "G", "B"), c = c(TRUE, FALSE, NA)) as.matrix(df, ) # as.matrix for a mixed data frame df1 <- data.frame(a = c(1:3), c = c(TRUE, FALSE,NA))
# as.matrix for a logical-numeric data frame as.matrix(df1, rownames.force = TRUE)
xd <- dist(matrix(1:12, nrow = 3)) as.matrix(xd) # as.matrix for a "dist" object
## POSIXlt plt <- as.POSIXlt(c("1970-01-01 00:00:00", "2038-01-19 03:14:07")) as.matrix(plt)
xn <- noquote(1:12)
as.matrix(xn) # as.matrix for a "noquote" object