Quickly create a factor
fact(x)# S3 method for default
fact(x)
# S3 method for character
fact(x)
# S3 method for numeric
fact(x)
# S3 method for integer
fact(x)
# S3 method for Date
fact(x)
# S3 method for POSIXt
fact(x)
# S3 method for logical
fact(x)
# S3 method for factor
fact(x)
# S3 method for fact
fact(x)
# S3 method for pseudo_id
fact(x)
# S3 method for haven_labelled
fact(x)
A vector of equal length of x with class fact and factor. If
x was ordered, that class is added in between.
A vector of values
The order of the levels may be adjusted to these rules depending on the class
of x:
characterThe order of appearance
numeric/integer/Date/POSIXtBy the numeric order
logicalAs TRUE, FALSE, then NA if present
factorNumeric if levels can be safely converted, otherwise as they are
fact() can be about 5 times quicker than factor() or
as.factor() as it doesn't bother sorting the levels for non-numeric data
or have other checks or features. It simply converts a vector to a factor
with all unique values as levels with NAs included.
fact.factor() will perform several checks on a factor to include NA
levels and to check if the levels should be reordered to conform with the
other methods. The fact.fact() method simple returns x.
as_ordered()
Other factors:
as_ordered(),
char2fact(),
drop_levels(),
fact2char(),
fact_na()