[ top | up ]

Row Indexes

Syntax

row(x, as.factor=FALSE)

Description

If as.factor is FALSE, row takes a matrix as argument and returns an integer matrix with the same dimensions whose ij-th element is equal to i. If as.factor is TRUE, row the value is returned as a factor with levels labelled by the row names of x.

Examples

# extract the diagonal of a matrix dx <- x[row(x)==col(x)] # create an identity 5-by-5 matrix x <- matrix(0,nr=5,nc=5) x[row(x)==col(x)] <- 1