Column and Row Identification in a Matrix

DESCRIPTION:

Returns a matrix filled with integers each of which is the row or column number in which it resides.

USAGE:

col(x) 
row(x) 

REQUIRED ARGUMENTS:

x
matrix. Missing values ( NAs) are allowed.

VALUE:

integer matrix, containing the row number or column number of each element. If z<-row(x), z[i,j] is i for all j; if z<-col(x), z[i,j] is j for all i.

NOTE:

Do not confuse this function with the col parameter in graphics functions; see par for that use of col.

SEE ALSO:

, , .

EXAMPLES:

x[row(x)>col(x)] <- 0     # zero the strict lower triangle of x 
x[row(x)-col(x)==1]     # first sub-diagonal