cpp_fast_factor {IFC} | R Documentation |
Fast Factorize Vector
Description
Makes factor with Rcpp
Arguments
x |
a SEXP only NILSXP, LGLSXP, INTSXP, REALSXP, STRSXP, RAWSXP are handled. |
handleNA |
a bool specifying if NA should be returned as NA or if they should be attributed a unique integer. |
Details
returned object should not be of class ‘factor' so has to prevent malformed factor’ error when printing the result in R.
For this reason, it is aimed to be wrap in an R function to handle factor class / handleNA balance.
e.g. either:
- structure(cpp_fast_factor(df, TRUE), class = "factor"), or,
- structure(cpp_fast_factor(unclass(df), FALSE), levels = NULL)
Value
an IntegerVector, with attributes "levels" being the non-NA unique value(s) found and "lvs" the total number of unique values found (including NA).
Source
adaptation from Kevin Ushey code https://gallery.rcpp.org/articles/fast-factor-generation/