library(tibble)
library(lubridate)
library(dplyr)
sample <- tibble::tibble(Datetime = c("2023-08-15 6:00:00",
"2023-08-15 23:00:00",
"2023-08-16 6:00:00",
"2023-08-16 22:00:00",
"2023-08-17 6:30:00",
"2023-08-18 1:00:00"),
State = rep(c("wake", "sleep"), 3),
Id = "Participant")
#intervals from sample
sc2interval(sample)
#compare sample (y) and intervals (x)
sc2interval(sample) %>%
mutate(Datetime = int_start(Interval)) %>%
dplyr::left_join(sample, by = c("Id", "State"),
relationship = "many-to-many") %>%
head()
Run the code above in your browser using DataLab