I have a df akin to df1 where I want to break out the rows so that the HOURS column is in intervals of 4, shown in df2. How would I approach this problem and what packages are recommended?
IDs can have more than one sequence on a given day. For example, an ID can be listed 2-3 times on a given day, being assigned more than one unit and and more than one CODE.
The following are required:
- All categorical data must remain the same on child rows (e.g., CODE stays the same on every child row)
- If there is a remainder that is less than four, the remainder amount should be listed on the last line (e.g., df2; row B)
- If a child row starts or ends on the next date the date column should be updated accordingly (e.g., df2; row E)
df1 (current)
EMPLID TIME_RPTG_CD START_DATE_TIME END_DATE_TIME Hrs_Time_Worked
<chr> <chr> <dttm> <dttm> <dbl>
1 X00007 REG 2014-07-03 16:00:00 2014-07-03 02:00:00 10.0
df2 (desired)
EMPLID TIME_RPTG_CD START_DATE_TIME END_DATE_TIME Hrs_Time_Worked
<chr> <chr> <dttm> <dttm> <dbl>
1 X00007 REG 2014-07-03 16:00:00 2014-07-03 20:00:00 4.0
1 X00007 REG 2014-07-03 20:00:00 2014-07-04 24:00:00 4.0
1 X00007 REG 2014-07-04 24:00:00 2014-07-04 02:00:00 2.0