matriks membuat matriks dari kumpulan nilai yang diberikan. as.matrix mencoba mengubah argumennya menjadi matriks. is.matrix menguji apakah argumennya adalah matriks (ketat).
matrix(data = NA, nrow = 1, ncol = 1, byrow = FALSE,
dimnames = NULL)<p></p><p>as.matrix(x, …)
# S3 method for data.frame
as.matrix(x, rownames.force = NA, …)</p><p>is.matrix(x)</p>
| Parameter | Deskripsi |
|---|---|
data |
an optional data vector (including a list or expression vector). Non-atomic classed R objects are coerced by as.vector and all attributes discarded. |
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: NULL or a list of length 2 giving the row and column names respectively. An empty list is treated as NULL, and a list of length one as row names. The list can be named, and the list names will be used as names for the dimensions. |
x |
an R object. |
… |
additional arguments to be passed to or from methods. |
rownames.force |
logical indicating if the resulting matrix should have character (rather than NULL) rownames. The default, NA, uses NULL rownames if the data frame has ‘automatic’ row.names or for a zero-row data frame. |
# NOT RUN {
is.matrix(as.matrix(1:10))
!is.matrix(warpbreaks) # data.frame, NOT matrix!
warpbreaks[1:10,]
as.matrix(warpbreaks[1:10,]) # using as.matrix.data.frame(.) method
## Example of setting row and column names
mdat <- matrix(c(1,2,3, 11,12,13), nrow = 2, ncol = 3, byrow = TRUE,
dimnames = list(c("row1", "row2"),
c("C.1", "C.2", "C.3")))
mdat
# }