Может быть, это то, что вы ищете:
# Made up weekdays as an example
Absenteeism <- data.frame(Weekday = (1:10)%%7+1)
# Create a new column with the explicit name
Absenteeism$categoryName = ifelse( Absenteeism$Weekday <= 3, "Beginning of Week", "End of Week")
# Create a new factors column with levels 0 and 1
Absenteeism$category = factor(ifelse( Absenteeism$Weekday <= 3, 0, 1))
Результаты:
> Absenteeism
Weekday categoryName category
1 2 Beginning of Week 0
2 3 Beginning of Week 0
3 4 End of Week 1
4 5 End of Week 1
5 6 End of Week 1
6 7 End of Week 1
7 1 Beginning of Week 0
8 2 Beginning of Week 0
9 3 Beginning of Week 0
10 4 End of Week 1
> summary(Absenteeism)
Weekday categoryName category
Min. :1.00 Length:10 0:5
1st Qu.:2.25 Class :character 1:5
Median :3.50 Mode :character
Mean :3.70
3rd Qu.:4.75
Max. :7.00