whichRowCol: Identify Rows and Columns

View source: R/whichRowCol.R

whichRowColR Documentation

Identify Rows and Columns

Description

Identifies the row and column numbers (indexes) of TRUE values in a logical matrix.

Usage

whichRowCol(x, which = "both")

Arguments

x

a logical matrix. Missing values are treated as FALSE

which

a character string indicating what should be returned.

Value

A matrix of the row and column number if which is "both." Otherwise a named vector of the row number, if which is "row," or column number, if which is "col." Only the first character is needed.

Note

Some comparisons, %in% for example, will return a vector rather than a matrix and cause whichRowCol to fail.

See Also

row, col, which

Examples


# Simple case to find a single value
whichRowCol(matrix(1:20, ncol=4) == 16)
# Where are the missing values in a data set?
library(smwrData)
data(MenomineeMajorIons)
whichRowCol(sapply(MenomineeMajorIons, is.na))

USGS-R/smwrBase documentation built on Oct. 18, 2022, 9:55 a.m.