Convert day of week number to weekday name in R
问题 I have a column in a dataframe that contains the day number ( 0 through 6, 0=Sunday, 1=Monday, etc) and I need to convert that to the day name. How can I do this? Sample data: df <- data.frame(day_number=0:6) 回答1: Simple way with dplyr. library(dplyr) df <- data.frame(day_number=0:6) df$day_number <- recode(df$day_number, "0"="Sunday", "1"="Monday", "2"="Tuesday", "3"="Wednesday", "4"="Thursday", "5"="Friday", "6"="Saturday") 回答2: Treat the column as a factor with day name as label: x <- data