recode()

recode()

The recode() function can be used to rename any of the values of a variable.

Example:

# recode the variable `Year` and save it is a new column in the data frame
Fingers$Year_recode <- recode(Fingers$Year, "1" = "First", "2" = "Second", "3" = "Third", "4" = "Fourth")
# check the data
head(select(Fingers, Year, Year_recode))

Example output:
Output of the head function. Shows 6 rows of Year and Year_recode.