powered by
Efficiently recodes text values using C++ hash tables. This is a drop-in replacement for txt_recode but significantly faster for large vectors.
txt_recode
txt_recode_fast(x, from = c(), to = c(), na.rm = FALSE)
A character vector of the same length as x where values matching from are replaced by corresponding values in to
x
from
to
A character vector to recode
A character vector with values of x which you want to recode
A character vector with values you want to use to recode to
Logical, if set to TRUE, will put all values of x which have no matching value in from to NA. Defaults to FALSE
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.
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