View source: R/restore_factor_info.R
restore_factor_info | R Documentation |
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.
restore_factor_info(data)
data |
the data.frame to which labelr-specific factor attribute meta-
data may have been applied via |
A data.frame.
# 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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.