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.
- col: the value of the col(x)[i,j]-th element
is the same for all of the col(x)[,j] elements.
- row: the value of the row(x)[i,j]-th element
is the same for all of the row(x)[i,] elements.
See Also
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