I have dataset
wrong=structure(list(SAP = c("W609", "W609", "W609", "W609", "W609",
"W609", "W609", "W609", "W609"), weekd = c(1L, 1L, 1L, 2L, 2L,
2L, 3L, 3L, 3L), tab = c(1003L, 1004L, 1005L, 1001L, 1003L, 1004L,
1002L, 1003L, 1005L), date = c(20220404L, 20220404L, 20220404L,
20220405L, 20220405L, 20220405L, 20220406L, 20220406L, 20220406L
), kod = c(690L, 690L, 690L, 801L, 690L, 690L, 690L, 690L, 690L
), timeStart = c(12L, 12L, 10L, 10L, 12L, 12L, 10L, 12L, 12L),
timeEnd = c(22L, 22L, 20L, 20L, 22L, 22L, 20L, 22L, 22L)), class = "data.frame", row.names = c(NA,
-9L))
How to do that if on a particular SAP on a certain day of the week work strictly 3 people no more and no less (tab column) and some tabs have same timeStart and timeEnd, for example, two tabs = 1003 and tab= 1004
the same time work from 12-22, so i need to change for any one tab randomly 1 hour less, for example 11-21.
Well, for example, manually, I did it like this desired output
SAP weekd tab date kod timeStart timeEnd
1 W609 1 1003 20220404 690 12 22
2 W609 1 1004 20220404 690 **11 21**
3 W609 1 1005 20220404 690 10 20
4 W609 2 1001 20220405 801 10 20
5 W609 2 1003 20220405 690 **11 21**
6 W609 2 1004 20220405 690 12 22
7 W609 3 1002 20220406 690 10 20
8 W609 3 1003 20220406 690 **11 21**
9 W609 3 1005 20220406 690 12 22
In other words, I randomly chose a one tab with the same timeStart and timeEnd and lowered them by one hour.
Accordingly, if we had three tabs with the same timestart and timeend, well, for example, 12-22, then one would have 10-20, the second had 11-21, the third had 12-22.
How can I make these transformations correctly? Thank you for your help.