ft_merge: Merge Two Factors and Retain Unique Levels

View source: R/single_replace.R

ft_mergeR Documentation

Merge Two Factors and Retain Unique Levels

Description

Merges two factor vectors into one, retaining unique levels from both factors.

Usage

ft_merge(factor_vec1, factor_vec2, level_order = NULL)

Arguments

factor_vec1

The first factor vector.

factor_vec2

The second factor vector.

level_order

A character vector specifying the desired order of levels. If NULL, levels are ordered by their first appearance.

Value

A factor vector containing the combined data from both factors with unique levels.

Author(s)

Kai Guo

Examples

# Example factor vectors
factor_vec1 <- factor(c('apple', 'banana', 'cherry'))
factor_vec2 <- factor(c('banana', 'date', 'fig', 'grape'))

# Merge factors and retain unique levels
ft_merge(factor_vec1, factor_vec2)

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