dim {base} | R Documentation

## Dimensions of an Object

### Description

Retrieve or set the dimension of an object.

### Usage

    dim(x)
    dim(x) <- values

### Details

The functions `dim` and `dim<-` are generic.

For an array (and hence in particular, for a matrix) they retrieve or set the `dim` attribute of the object. It is always `integer` or `NULL`.

`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'').

### See Also

`ncol`, `nrow` and `dimnames`.

### Examples

    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]

[Package Contents]