N <- 60
# Dataset with epoch = 1min
dataset1 <-
tibble::tibble(
Id = rep("A", N),
Datetime = lubridate::as_datetime(0) + lubridate::minutes(1:N),
MEDI = sample(c(sample(1:249, N / 2), sample(250:1000, N / 2))),
)
# Dataset with epoch = 30s
dataset2 <-
tibble::tibble(
Id = rep("B", N),
Datetime = lubridate::as_datetime(0) + lubridate::seconds(seq(30, N * 30, 30)),
MEDI = sample(c(sample(1:249, N / 2), sample(250:1000, N / 2))),
)
dataset.combined <- rbind(dataset1, dataset2)
dataset1 %>%
dplyr::reframe("TAT >250lx" = duration_above_threshold(MEDI, Datetime, threshold = 250))
dataset1 %>%
dplyr::reframe(duration_above_threshold(MEDI, Datetime, threshold = 250, as.df = TRUE))
# Group by Id to account for different epochs
dataset.combined %>%
dplyr::group_by(Id) %>%
dplyr::reframe("TAT >250lx" = duration_above_threshold(MEDI, Datetime, threshold = 250))
Run the code above in your browser using DataLab