Learn R Programming

icd (version 3.3)

refactor: Refactor by integer matching levels in C++

Description

Slightly slower for small factors, three times faster for one hundred million elements with two million new levels. Three times faster for any n > 1e6. With NA values, margin is smaller, but still beats base factor.

Usage

refactor(x, levels, na.rm = FALSE, exclude_na = TRUE)

Arguments

exclude_na

Simpler equivalent to base::factor exclude. By default, refactor will not count NA as a factor level if there are NA elements in the input data.

Examples

Run this code
# NOT RUN {
  f <- factor(c(1, 2, 3))
  icd:::refactor(f, c("2", "3"))
  f <- factor(c(1, 2, NA))
  icd:::refactor(f, c("2", "3", NA))
# }

Run the code above in your browser using DataLab