fct_to_num | R Documentation |
Easily convert a factor to numeric without losing information.
fct_to_num(x)
x |
A factor. |
A numeric.
library(dplyr)
set.seed(1)
num <- rnorm(10)
# Without fct_to_numeric
data.frame(fac = factor(num)) %>%
mutate(bad_num = as.numeric(fac))
# With fct_to_numeric
data.frame(fac = factor(num)) %>%
mutate(good_num = fct_to_num(fac))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.