Hi, in R usually factors are used to work with categorical variables.
an example
library(tidyverse)
# generate some data
df <- tibble(gender = c(1, 0, 2, 1, 2, 1, 0))
# convert numerical variable to factor
df <- df %>%
mutate(gender = factor(gender,
levels = c(1, 2, 0),
labels = c("male", "female", "blank")))
df$gender
#> [1] male blank female male female male blank
#> Levels: male female blank
# converting to a numerical vector is still possible
as.integer(df$gender)
#> [1] 1 3 2 1 2 1 3
https://r4ds.had.co.nz/factors.html is a very good introduction in how to work with factor variables. And https://r4ds.had.co.nz/ if you are a newbie who would like to start working with R.