col(x)
col takes a matrix as argument and returns
an integer matrix with the same dimensions.
The ij-th element of col(x) is equal to j.
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