restore_factor_info {labelr}R Documentation

Restore Factor Status, Levels to a Character Column of a Labeled Data Frame

Description

restore_factor_info searches a data.frame for labelr-specific factor meta-data (added by add_factor_info()) and, if found, uses that information to coerce a character vector that was formerly a factor back into a factor, with former levels and (if applicable) "ordered" factor status, as well.

Usage

restore_factor_info(data)

Arguments

data

the data.frame to which labelr-specific factor attribute meta- data may have been applied via add_factor_info.

Value

A data.frame.

Examples

# this function does not strictly require prior or other use of labelr
zz <- add_factor_info(iris) # we'll find out what this does
sapply(zz, class) # Species is a factor
zz$Species <- as.character(zz) # now it's a character
sapply(zz, class) # yup, it's a character
zz <- restore_factor_info(zz) # we'll find out what this does
sapply(zz, class) # now it's back to a factor
levels(zz$Species) # levels are back, too.

[Package labelr version 0.1.5 Index]