Created
July 6, 2022 19:00
-
-
Save alexpghayes/a2a436a24560edf3307267eaffb38500 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` r | |
library(dplyr) | |
#> | |
#> Attaching package: 'dplyr' | |
#> The following objects are masked from 'package:stats': | |
#> | |
#> filter, lag | |
#> The following objects are masked from 'package:base': | |
#> | |
#> intersect, setdiff, setequal, union | |
d <- tibble( | |
GENDER = sample(1:3, 10, replace = TRUE) | |
) | |
d |> | |
mutate( | |
gender_chr = case_when( | |
GENDER == 1 ~ "male", | |
GENDER == 2 ~ "female", | |
TRUE ~ "other" | |
), | |
gender_fct = as.factor(gender_chr) | |
) | |
#> # A tibble: 10 × 3 | |
#> GENDER gender_chr gender_fct | |
#> <int> <chr> <fct> | |
#> 1 1 male male | |
#> 2 3 other other | |
#> 3 3 other other | |
#> 4 2 female female | |
#> 5 2 female female | |
#> 6 3 other other | |
#> 7 1 male male | |
#> 8 1 male male | |
#> 9 3 other other | |
#> 10 1 male male | |
``` | |
<sup>Created on 2022-07-06 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1.9000)</sup> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment