Learn R Programming

fritools (version 4.6.0)

char2factor: 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))

Value

A factor.

Arguments

x

A character vector.

levels

The levels to use, see factor.

See Also

Other vector functions: escape_non_ascii(), file_string(), powers_of_ten

Examples

Run this code
x <- c("beech", "oak", "spruce", "fir")
char2factor(x)

Run the code above in your browser using DataLab