Learn R Programming

tall (version 0.5.1)

txt_recode_fast: Fast text recoding (Rcpp version)

Description

Efficiently recodes text values using C++ hash tables. This is a drop-in replacement for txt_recode but significantly faster for large vectors.

Usage

txt_recode_fast(x, from = c(), to = c(), na.rm = FALSE)

Value

A character vector of the same length as x where values matching from are replaced by corresponding values in to

Arguments

x

A character vector to recode

from

A character vector with values of x which you want to recode

to

A character vector with values you want to use to recode to

na.rm

Logical, if set to TRUE, will put all values of x which have no matching value in from to NA. Defaults to FALSE

Details

This function uses C++ hash tables for O(1) lookup time, making it much faster than the pure R implementation, especially for large datasets.

Performance improvement: ~50-100x faster than base R txt_recode for vectors with 100K+ elements.

Examples

Run this code
x <- c("NOUN", "VERB", "NOUN", "ADV")
txt_recode_fast(x,
  from = c("VERB", "ADV"),
  to = c("conjugated verb", "adverb")
)

Run the code above in your browser using DataLab