This function converts a vector to a factor while preserving its "label" attribute.

as_factor_preserve_label(x)

Arguments

x

A vector to be converted to a factor.

Value

A factor with the original "label" attribute preserved.

Examples

if (FALSE) { # \dontrun{
  # Example usage:
  vec <- c("A", "B", "C")
  attr(vec, "label") <- "Example Label"
  factor_vec <- as_factor_preserve_label(vec)
  print(factor_vec)
  print(attr(factor_vec, "label"))
} # }