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.
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)
#> column row
#> 2 1 1
#> 1 2 2
#> 3 2 3
# Find positions of value 2
valueCoordinates(df, 2)
#> column row
#> 1 2 2
#> 2 3 2
# Find positions where values exceed 2
valueCoordinates(df, 2, function(x, y) x > y)
#> column row
#> 2 1 1
#> 1 3 3
# Find positions of values in range [1,3]
valueCoordinates(df, c(1, 3), function(x, y) x >= y[1] & x <= y[2])
#> column row
#> 1 1 1
#> 5 1 2
#> 3 2 2
#> 4 3 1
#> 2 3 3
#> 6 3 3