We can use factor with labels specified for corresponding levels
library(dplyr) DF <- DF %>% mutate(Station = factor(Station, levels = c("DA056", "AB786"), labels = c("Happy", "Sad"))) DF$Station #[1] Happy Happy Happy Sad Sad Sad #Levels: Happy Sad
Or with recode
DF %>% mutate(Station = recode(Station, DA056 = 'Happy', AB786 = 'Sad')) # Station Level #1 Happy 100 #2 Happy 101 #3 Happy 102 #4 Sad 201 #5 Sad 202 #6 Sad 203
If there are many values to be changed, a better option is a join after creating a key/val dataset
keyval <- data.frame(Station = c("DA056", "AB786"), val = c("Happy", "Sad"), stringsAsFactors = FALSE) DF %>% left_join(keyval) %>% mutate(Station = coalesce(val, Station))
Or with base R
DF$Station <- with(df, factor(Station, levels = c("DA056", "AB786"), labels = c("Happy", "Sad")))
Stationare NOT row names. It is a separate columnrow nameunder station column.