dim {base} | R Documentation |
Retrieve or set the dimension of an object.
dim(x) dim(x) <- value
x |
an R object, for example a matrix, array or data frame. |
value |
For the default method, either NULL or
a numeric vector which coerced to integer (by truncation). |
The functions dim
and dim<-
are generic.
dim
has a method for data.frame
s, which returns
the length of the row.names
attribute of x
and the
length of x
(the numbers of “rows” and “columns”).
For an array (and hence in particular, for a matrix) dim
retrieves
the dim
attribute of the object. It is NULL
or a vector
of mode integer
.
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
x <- 1:12 ; dim(x) <- c(3,4) x # simple versions of nrow and ncol could be defined as follows nrow0 <- function(x) dim(x)[1] ncol0 <- function(x) dim(x)[2]