ft_encode {fctutils}R Documentation

Encode Factor Levels into Numeric Codes

Description

Converts the levels of a factor vector into numeric codes, optionally using a provided mapping.

Usage

ft_encode(factor_vec, mapping = NULL)

Arguments

factor_vec

A factor vector to encode.

mapping

An optional named vector providing the numeric code for each level.

Value

A numeric vector with encoded values.

Author(s)

Kai Guo

Examples

# Example factor vector
factor_vec <- factor(c('low', 'medium', 'high', 'medium'))

# Encode without mapping
ft_encode(factor_vec)

# Encode with custom mapping
custom_mapping <- c('low' = 1, 'medium' = 2, 'high' = 3)
ft_encode(factor_vec, mapping = custom_mapping)

[Package fctutils version 0.0.7 Index]