# Example formats
age. <- discrete_format(
"under 18" = 0:17,
"18 to under 25" = 18:24,
"25 to under 55" = 25:54,
"55 to under 65" = 55:64,
"65 and older" = 65:100)
# Example data frame
my_data <- dummy_data(1000)
# Call function
my_data <- my_data |> recode("age_group1", age = age.)
# Formats can also be passed as characters
my_data <- my_data |> recode("age_group2", age = "age.")
# Multilabel recode
sex. <- discrete_format(
"Total" = 1:2,
"Male" = 1,
"Female" = 2)
income. <- interval_format(
"Total" = 0:99999,
"below 500" = 0:499,
"500 to under 1000" = 500:999,
"1000 to under 2000" = 1000:1999,
"2000 and more" = 2000:99999)
multi_data <- my_data |> recode_multi(sex = sex., income = income.)
Run the code above in your browser using DataLab