View source: R/metric_threshold_for_duration.R
| threshold_for_duration | R Documentation | 
This function finds the threshold for which light levels are above/below for
a given duration. This function can be considered as the inverse of
duration_above_threshold.
threshold_for_duration(
  Light.vector,
  Time.vector,
  duration,
  comparison = c("above", "below"),
  epoch = "dominant.epoch",
  na.rm = FALSE,
  as.df = FALSE
)
| Light.vector | Numeric vector containing the light data. | 
| Time.vector | Vector containing the time data. Can be POSIXct, hms, duration, or difftime. | 
| duration | The duration for which the threshold should be found. Can be either a
duration or a string. If it is a string, it needs to be a valid
duration string, e.g.,  | 
| comparison | String specifying whether light levels above or below the threshold
should be considered. Can be either  | 
| epoch | The epoch at which the data was sampled. Can be either a
duration or a string. If it is a string, it needs to be
either  | 
| na.rm | Logical. Should missing values (NA) be removed for the calculation?
Defaults to  | 
| as.df | Logical. Should a data frame with be returned? If  | 
Single numeric value or single column data frame.
Other metrics: 
bright_dark_period(),
centroidLE(),
disparity_index(),
dose(),
duration_above_threshold(),
exponential_moving_average(),
frequency_crossing_threshold(),
interdaily_stability(),
intradaily_variability(),
midpointCE(),
nvRC(),
nvRD(),
nvRD_cumulative_response(),
period_above_threshold(),
pulses_above_threshold(),
timing_above_threshold()
N <- 60
# Dataset with 30 min < 250lx and 30min > 250lx
dataset1 <-
  tibble::tibble(
    Id = rep("A", N),
    Datetime = lubridate::as_datetime(0) + lubridate::minutes(1:N),
    MEDI = sample(c(sample(1:249, N / 2, replace = TRUE), 
                    sample(250:1000, N / 2, replace = TRUE))),
  )
dataset1 %>%
  dplyr::reframe("Threshold above which for 30 mins" = 
                   threshold_for_duration(MEDI, Datetime, duration = "30 mins"))
dataset1 %>%
  dplyr::reframe("Threshold below which for 30 mins" = 
                   threshold_for_duration(MEDI, Datetime, duration = "30 mins",
                                          comparison = "below"))
dataset1 %>%
  dplyr::reframe(threshold_for_duration(MEDI, Datetime, duration = "30 mins",
                                        as.df = TRUE))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.