R Group Hours by Text

Viewed 30

Hi I am trying to group 24 hours into three groups as follows below in a new column:

Year  Hours  Users
2021    0     2332323
2021    1     2222323
2021    2     6332323
2021    3     9222323
###etc up to hours 23

My goal is to add a new column which gives each time a specific time of day text as follows, with the goal of having an end new column with hours 5 to 12 as "Morning", 13 TO 20 as "Evening", and lastly, 21 to 4 as "Night". Can anyone help to understand how I should create this column?

Year  Hours  Users      HourType
2021    0     2332323    Night
2021    1     2222323    Night
2021    2     6332323    Night
2021    3     9222323    Night
2021    4     1222323    Morning
2021    5     1222323    Morning
###etc up to hours 23
0 Answers
Related