cpp_fast_factor | R Documentation |
Makes factor with Rcpp
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. |
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)
an IntegerVector, with attributes "levels" being the non-NA unique value(s) found and "lvs" the total number of unique values found (including NA).
adaptation from Kevin Ushey code https://gallery.rcpp.org/articles/fast-factor-generation/
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.