Skip to contents

Relabel extrema with sequential labels after filtering

Usage

relabel.extrema(extrema.df, sort.ascending = NULL)

Arguments

extrema.df

A data frame of extrema (output from extrema.summary or a filtered subset) containing columns: label, vertex, value, type, etc.

sort.ascending

Logical. If TRUE, sort by value ascending (for minima). If FALSE, sort by value descending (for maxima). Default is NULL, which automatically uses FALSE for maxima and TRUE for minima based on the 'type' column.

Value

A data frame with the same structure as input but with relabeled extrema. Maxima are labeled M1, M2, ... in decreasing order of value. Minima are labeled m1, m2, ... in increasing order of value.

Details

After filtering extrema based on criteria such as hop.idx, extremality radius, or other properties, the labels (M1, M2, ..., m1, m2, ...) become non-sequential. This function reassigns labels to maintain sequential numbering in the appropriate order.

If the input contains both maxima and minima, they are relabeled separately within their respective types.

Examples

extrema.df <- data.frame(
  label = c("M4", "M7", "m9", "m3"),
  vertex = c(4, 7, 9, 3),
  value = c(1.2, 0.9, -0.8, -0.3),
  type = c("max", "max", "min", "min"),
  hop.idx = c(3, 2, 4, 1)
)

relabeled <- relabel.extrema(extrema.df)
relabeled[, c("label", "vertex", "type")]