There is a table:
time<-c("02:20:00",
"02:35:00",
"02:40:00",
"03:35:00",
"03:40:00",
"04:50:00",
"04:55:00",
"05:00:00",
"05:00:00",
"05:05:00",
"05:10:00",
"05:10:00",
"05:15:00",
"05:20:00",
"05:25:00",
"05:15:00",
"05:20:00",
"05:15:00",
"05:20:00")
id<-c(1,2,2,3,3,4,4,4,5,5,5,6,6,6,6,7,7,8,8)
value<-rep(1,19)
df<-data.frame(id, time, value)
There are eight id's which occupy the cells from 5 to 20 minutes. One cell can be occupied at the same time only with one id. If cell 1 is occupied with id 1, the id 2 has to get another one cell. I use this code:
df2<-df %>%
group_by(time) %>%
mutate(new_names = paste0("id", 1:n())) %>%
pivot_wider(names_from = new_names)
The Problem is, if the previous cell is free again, switchs the next one id in the cell 1 back.
I want that this id stays in the cell 2 for the whole time. I would like to get the following output:
Could You please help me?
Thanks in advance! Inna