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)

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.
Value
returns an integer or factor matrix 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.
See Also
diag, ncol, slice.index.
Examples
x <- matrix(1:10, nrow=5)
col(x)
#     [,1] [,2]
#[1,]    1    2
#[2,]    1    2
#[3,]    1    2
#[4,]    1    2
#[5,]    1    2

col(x, TRUE) # [,1] [,2] #[1,] 1 2 #[2,] 1 2 #[3,] 1 2 #[4,] 1 2 #[5,] 1 2 #Levels: 1 2

Package base version 4.0.0-28
Package Index