extract_numeric_values {Tivy} | R Documentation |
Extract length values from column names
Description
Helper function to extract numerical length values from column names. Handles different naming patterns like "length_8.5", "weighted_9", "8", etc. Uses multiple extraction strategies to ensure robust parsing of column names.
Usage
extract_numeric_values(
column_names,
use_fallback = TRUE,
fallback_type = "sequential",
verbose = FALSE
)
Arguments
column_names |
Character vector of column names. |
use_fallback |
Logical. If TRUE, uses fallback strategy when numeric values cannot be extracted. |
fallback_type |
Character. Type of fallback to use when use_fallback = TRUE. Options: "sequential", "ones", "zeros". |
verbose |
Logical. Print information about extraction strategy used. |
Details
The function uses the following extraction strategies in order:
Specific prefixes: "length_", "weighted_", "pond_" followed by numbers
Purely numeric column names
General pattern: extracts first number found in each name
Fallback: uses specified fallback strategy if previous methods fail
Value
Numeric vector of length values extracted from column names.
Examples
extract_numeric_values(c("length_8.5", "weighted_10", "pond_12"))
extract_numeric_values(c("8", "10.5", "12"))
extract_numeric_values(c("size_8", "data_10.5", "value_12"))
extract_numeric_values(c("length_8", "no_numbers"), use_fallback = FALSE)
extract_numeric_values(c("bad_name1", "bad_name2"), fallback_type = "ones")