I have a dataset. You can see example of my dataset enter image description here
I have 12000 row and 50 student in my dataset. I want to determine session number for every row. If there is more than half an hour between two times in a student's lines, I will take these lines as a different session. This is done in the code block below. but do not reset the number of sessions for each student. The number of sessions should continue where it left off. How can I do it.
My code:
data1 <- data %>%
arrange(Name, Time) %>%
group_by(Name) %>%
mutate(session_diff = cumsum(c(0, diff(Time) > minutes(30))))
for example, enter image description here
This is done in the code block below. but do not reset the number of sessions for each student. The number of sessions should continue where it left off.