col
Column and Row Identification in a Matrix

Description

Return a matrix filled with integers, where each element corresponds to the number of its column or row.

Usage

col(x, as.factor = FALSE)
row(x, as.factor = FALSE)
.col(dim)
.row(dim)

Arguments

x a matrix. Missing values (NAs) are allowed.
as.factor a logical value. If FALSE (the default), the output is an integer matrix. If TRUE, the outpus is a factor matrix.
dim a vector of two nonnegative integers giving the dimensions of a matrix.
Value
col(x) and row(x) return an integer with the same dimensions as the x matrix, but where each element contains the number of the column or row of which it is a member.
col(x, as.factor=TRUE) and row(x, as.factor=TRUE) return a factor with the same dimensions as x. Instead of the column or row number in each entry, the column or row name is used (or, if there are no column or row names, the column or row number as a string).
.col(dim) and .row(dom) return the same thing as col(array(1, dim=dim)) and row(array(1, dim=dim)), respectively.
See Also
diag, ncol, slice.index.
Examples
x <- matrix(101:106, nrow=3, ncol=2,
         dimnames=list(Rows=paste0("R",1:3), Cols=paste0("C",1:2)))
col(x)
col(x, as.factor = TRUE)
row(x)
.row(dim(x))
Package base version 6.0.0-69
Package Index