char2factor {fritools} | R Documentation |
Convert a Character Vector Into a Factor
Description
I often need a factor with levels the unique values of a character vector (for example: to prevent ggplot2 from sorting the character vector).
Usage
char2factor(x, levels = unique(x))
Arguments
x |
A character vector. |
levels |
The levels to use, see |
Value
A factor.
See Also
Other vector functions:
escape_non_ascii()
,
file_string()
Examples
x <- c("beech", "oak", "spruce", "fir")
char2factor(x)
[Package fritools version 4.5.0 Index]