Description Usage Arguments Value Examples

Similar to `base::as.factor`

but much faster and only for converting character vector to factor.

1 | ```
charToFact(x, decreasing=FALSE, nThread=getOption("kit.nThread"))
``` |

`x` |
A vectorof type character |

`decreasing` |
A boolean. Whether to order levels in decreasing order or not. Default is |

`nThread` |
Number of thread to use. |

The character vector input as a factor. Please note that, unlike `as.factor`

, `NA`

levels are preserved.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | ```
x = c("b","A","B","a","\xe4","a")
Encoding(x) = "latin1"
identical(charToFact(x), as.factor(x))
identical(charToFact(c("a","b",NA,"a")), addNA(as.factor(c("a","b",NA,"a"))))
# Benchmarks
# ----------
# x = sample(letters,3e7,TRUE)
# microbenchmark::microbenchmark(
# kit=kit::charToFact(x,nThread = 1L),
# base=as.factor(x),
# times = 5L
# )
# Unit: milliseconds
# expr min lq mean median uq max neval
# kit 188 190 196 194 200 208 5
# base 1402 1403 1455 1414 1420 1637 5
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.