valueCoordinates: Locate Specific Values in a Data Frame

View source: R/valueCoordinates.R

valueCoordinatesR Documentation

Locate Specific Values in a Data Frame

Description

Finds the positions (row and column indices) of values in a data.frame that match specified criteria. This function is useful for locating particular values within large datasets.

Usage

valueCoordinates(df, value = NA, eq_fun = value_check)

Arguments

df

A data.frame to search

value

The target value to find (default: NA)

eq_fun

A comparison function that takes two parameters: the current value from the data.frame and the target value. Returns TRUE for matches. Default uses internal value_check function; handles NA values.

Value

A data.frame with two columns:

column

Column indices where matches were found

row

Row indices where matches were found

Results are sorted by column, then by row.

Examples

# Sample data.frame
df <- data.frame(
  a = c(1, NA, 3),
  b = c(NA, 2, NA),
  c = c(3, 2, 1)
)

# Find NA positions
valueCoordinates(df)

# Find positions of value 2
valueCoordinates(df, 2)

# Find positions where values exceed 2
valueCoordinates(df, 2, function(x, y) x > y)

# Find positions of values in range [1,3]
valueCoordinates(df, c(1, 3), function(x, y) x >= y[1] & x <= y[2])


stenographer documentation built on April 4, 2025, 4:55 a.m.