as.numeric_discrete | R Documentation |
Converts a factor with numeric levels, or, a character vector with numeric values to a numeric vector using as.numeric_factor, or, as.numeric_character respectively. If an unnamed numeric vector is passed, it will be returned as a named numeric vector, if this vector is continuous, it will be returned discretised (by calling ts_discrete), the labels will be rounded to 'signif(x, digits = 4).
as.numeric_discrete(x, keepNA = FALSE, sortUnique = FALSE)
x |
A factor with levels that are numeric, or, a character vector representing numbers. |
keepNA |
Keep NA values ( |
sortUnique |
Should the unique character/factor level values be sorted? (default = |
A named numeric vector with original factor levels / character values / numeric values as names.
# Continuous
i <- runif(10,0,9)
as.numeric_discrete(i)
# Integer
as.numeric_discrete(round(i))
# Factor with NAs
f <- factor(c(round(runif(9,0,9)),NA))
as.numeric_discrete(f)
as.numeric_discrete(f, keepNA = FALSE)
# Character vector
c <- c("Thank","you", "for", "the flowers")
as.numeric_discrete(c)
as.numeric_discrete(c, sortUnique = TRUE)
c <- c("Thank","you", "for", "the", "flowers")
as.numeric_discrete(c)
as.numeric_discrete(c, sortUnique = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.