N <- 60
# Dataset with continous period of >250lx for 35min
dataset1 <-
tibble::tibble(
Id = rep("A", N),
Datetime = lubridate::as_datetime(0) + lubridate::minutes(1:N),
MEDI = c(sample(1:249, N-35, replace = TRUE),
sample(250:1000, 35, replace = TRUE))
)
dataset1 %>%
dplyr::reframe("Period >250lx" = period_above_threshold(MEDI, Datetime, threshold = 250))
dataset1 %>%
dplyr::reframe("Period <250lx" = period_above_threshold(MEDI, Datetime, "below", threshold = 250))
# Dataset with continous period of 100-250lx for 20min
dataset2 <-
tibble::tibble(
Id = rep("B", N),
Datetime = lubridate::as_datetime(0) + lubridate::minutes(1:N),
MEDI = c(sample(c(1:99, 251-1000), N-20, replace = TRUE),
sample(100:250, 20, replace = TRUE)),
)
dataset2 %>%
dplyr::reframe("Period 250lx" = period_above_threshold(MEDI, Datetime, threshold = c(100,250)))
# Return data frame
dataset1 %>%
dplyr::reframe(period_above_threshold(MEDI, Datetime, threshold = 250, as.df = TRUE))
Run the code above in your browser using DataLab