Learn R Programming

fctutils (version 0.0.7)

ft_factorize: 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)

Value

A list of factor vectors with consistent levels.

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.

Author

Kai Guo

Examples

Run this code
# 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]])

Run the code above in your browser using DataLab