View source: R/txt_recode_fast.R
| txt_recode_fast | R Documentation |
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_fast(x, from = c(), to = c(), na.rm = FALSE)
x |
A character vector to recode |
from |
A character vector with values of |
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 |
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.
A character vector of the same length as x where values
matching from are replaced by corresponding values in to
x <- c("NOUN", "VERB", "NOUN", "ADV")
txt_recode_fast(x,
from = c("VERB", "ADV"),
to = c("conjugated verb", "adverb")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.