fact | R Documentation |

Quickly create a factor

```
fact(x)
## Default S3 method:
fact(x)
## S3 method for class 'character'
fact(x)
## S3 method for class 'numeric'
fact(x)
## S3 method for class 'integer'
fact(x)
## S3 method for class 'Date'
fact(x)
## S3 method for class 'POSIXt'
fact(x)
## S3 method for class 'logical'
fact(x)
## S3 method for class 'factor'
fact(x)
## S3 method for class 'fact'
fact(x)
## S3 method for class 'pseudo_id'
fact(x)
## S3 method for class 'haven_labelled'
fact(x)
```

`x` |
A vector of values |

`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 `NA`

s 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`

.

A vector of equal length of `x`

with class `fact`

and `factor`

. If
`x`

was `ordered`

, that class is added in between.

The order of the levels may be adjusted to these rules depending on the class
of `x`

:

`character`

The order of appearance

`numeric`

/`integer`

/`Date`

/`POSIXt`

By the numeric order

`logical`

As

`TRUE`

,`FALSE`

, then`NA`

if present`factor`

Numeric if levels can be safely converted, otherwise as they are

`as_ordered()`

Other factors:
`as_ordered()`

,
`char2fact()`

,
`drop_levels()`

,
`fact2char()`

,
`fact_na()`

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.