ft_factorize: Factorize Character Vectors with Consistent Levels

View source: R/fct_misc.R

ft_factorizeR Documentation

Factorize Character Vectors with Consistent Levels

Description

Converts one or more character vectors into factors, ensuring that they share the same levels.

Usage

ft_factorize(..., levels = NULL)

Arguments

...

Character vectors to factorize.

levels

An optional character vector specifying the levels. If NULL, levels are determined from the combined unique values of all vectors.

Value

A list of factor vectors with consistent levels.

Author(s)

Kai Guo

Examples

# Example character vectors
vec1 <- c('apple', 'banana', 'cherry')
vec2 <- c('banana', 'date', 'apple')

# Factorize with consistent levels
factors <- ft_factorize(vec1, vec2)
levels(factors[[1]])
levels(factors[[2]])

fctutils documentation built on Oct. 1, 2024, 1:07 a.m.