Learn R Programming

labelr (version 0.1.9)

get_all_factors: Put Data Frame Factor Level Information into a List

Description

get_all_factors returns a list of character vectors, where each character vector is a given factor variable's unique levels, and where the vector is given the same name as the factor variable itself. If the data.frame contains no factors, an empty (length 0) list is returned.

Usage

get_all_factors(data)

Value

A list of 0, 1, or more character variables.

Arguments

data

the data.frame you are checking for factor variables.

Examples

Run this code
class(get_all_factors(iris))
length(get_all_factors(iris))
zz <- iris
zz$u <- zz$Species # zz has two factor variables
class(get_all_factors(zz))
length(get_all_factors(zz))
get_all_factors(mtcars)
length(get_all_factors(mtcars))

Run the code above in your browser using DataLab