forcats/ 0000755 0001762 0000144 00000000000 14365570422 011723 5 ustar ligges users forcats/NAMESPACE 0000644 0001762 0000144 00000002006 14357073063 013140 0 ustar ligges users # Generated by roxygen2: do not edit by hand
S3method(as_factor,character)
S3method(as_factor,factor)
S3method(as_factor,logical)
S3method(as_factor,numeric)
export("%>%")
export(as_factor)
export(fct)
export(fct_anon)
export(fct_c)
export(fct_collapse)
export(fct_count)
export(fct_cross)
export(fct_drop)
export(fct_expand)
export(fct_explicit_na)
export(fct_infreq)
export(fct_inorder)
export(fct_inseq)
export(fct_lump)
export(fct_lump_lowfreq)
export(fct_lump_min)
export(fct_lump_n)
export(fct_lump_prop)
export(fct_match)
export(fct_na_level_to_value)
export(fct_na_value_to_level)
export(fct_other)
export(fct_recode)
export(fct_relabel)
export(fct_relevel)
export(fct_reorder)
export(fct_reorder2)
export(fct_rev)
export(fct_shift)
export(fct_shuffle)
export(fct_unify)
export(fct_unique)
export(first2)
export(last2)
export(lvls_expand)
export(lvls_reorder)
export(lvls_revalue)
export(lvls_union)
import(rlang)
importFrom(glue,glue)
importFrom(lifecycle,deprecated)
importFrom(magrittr,"%>%")
importFrom(stats,median)
forcats/LICENSE 0000644 0001762 0000144 00000000055 13764153133 012726 0 ustar ligges users YEAR: 2020
COPYRIGHT HOLDER: forcats authors
forcats/README.md 0000644 0001762 0000144 00000007671 14360013050 013175 0 ustar ligges users
# forcats
[](https://cran.r-project.org/package=forcats)
[](https://github.com/tidyverse/forcats/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/tidyverse/forcats?branch=main)
## Overview
R uses **factors** to handle categorical variables, variables that have
a fixed and known set of possible values. Factors are also helpful for
reordering character vectors to improve display. The goal of the
**forcats** package is to provide a suite of tools that solve common
problems with factors, including changing the order of levels or the
values. Some examples include:
- `fct_reorder()`: Reordering a factor by another variable.
- `fct_infreq()`: Reordering a factor by the frequency of values.
- `fct_relevel()`: Changing the order of a factor by hand.
- `fct_lump()`: Collapsing the least/most frequent values of a factor
into “other”.
You can learn more about each of these in `vignette("forcats")`. If
you’re new to factors, the best place to start is the [chapter on
factors](https://r4ds.hadley.nz/factors.html) in R for Data Science.
## Installation
# The easiest way to get forcats is to install the whole tidyverse:
install.packages("tidyverse")
# Alternatively, install just forcats:
install.packages("forcats")
# Or the the development version from GitHub:
# install.packages("devtools")
devtools::install_github("tidyverse/forcats")
## Cheatsheet
## Getting started
forcats is part of the core tidyverse, so you can load it with
`library(tidyverse)` or `library(forcats)`.
``` r
library(forcats)
library(dplyr)
library(ggplot2)
```
``` r
starwars %>%
filter(!is.na(species)) %>%
count(species, sort = TRUE)
#> # A tibble: 37 × 2
#> species n
#>
#> 1 Human 35
#> 2 Droid 6
#> 3 Gungan 3
#> 4 Kaminoan 2
#> 5 Mirialan 2
#> 6 Twi'lek 2
#> 7 Wookiee 2
#> 8 Zabrak 2
#> 9 Aleena 1
#> 10 Besalisk 1
#> # … with 27 more rows
```
``` r
starwars %>%
filter(!is.na(species)) %>%
mutate(species = fct_lump(species, n = 3)) %>%
count(species)
#> # A tibble: 4 × 2
#> species n
#>
#> 1 Droid 6
#> 2 Gungan 3
#> 3 Human 35
#> 4 Other 39
```
``` r
ggplot(starwars, aes(x = eye_color)) +
geom_bar() +
coord_flip()
```

``` r
starwars %>%
mutate(eye_color = fct_infreq(eye_color)) %>%
ggplot(aes(x = eye_color)) +
geom_bar() +
coord_flip()
```

## More resources
For a history of factors, I recommend [*stringsAsFactors: An
unauthorized
biography*](https://simplystats.github.io/2015/07/24/stringsasfactors-an-unauthorized-biography/)
by Roger Peng and [*stringsAsFactors =
\*](https://notstatschat.tumblr.com/post/124987394001/stringsasfactors-sigh)
by Thomas Lumley. If you want to learn more about other approaches to
working with factors and categorical data, I recommend [*Wrangling
categorical data in R*](https://peerj.com/preprints/3163/), by Amelia
McNamara and Nicholas Horton.
## Getting help
If you encounter a clear bug, please file a minimal reproducible example
on [Github](https://github.com/tidyverse/forcats/issues). For questions
and other discussion, please use
[community.rstudio.com](https://community.rstudio.com/).
forcats/data/ 0000755 0001762 0000144 00000000000 12754676654 012652 5 ustar ligges users forcats/data/gss_cat.rda 0000644 0001762 0000144 00000217341 12754704400 014752 0 ustar ligges users BZh91AY&SYC]@ UU ᖘt|$}u3`Zh!ҬDCD = Ѡ: (
/A{@4 ^z(TքP R((UU@ )G )=t6"ҏLeJkFȨU
l-jafiz5+U9R P lҪm()VRI@PڶiZiJkjlf
MEbE-:
tT֮Sz
J=P (D r
!U4-` 0H P (
@ @l@ր ʠ C=1pQzTE tDJ
JEP={
P Sѥ*@-͖1b)oVڭ6D%h
jdF!fPP`
t4l)Z0 B:
ht: į@yP(P U^ƴ4R ( @R" T% J $IP
B%PJ
Q"Un*zJ(
2 "
ȑ S B!I44)hSmz$2 L jx"HBFDz1P= d4 O$DFP 2 RTH5
4 JHOJyMģ6zdz(zOM6Q*`*~,xu\jO