period_above_threshold {LightLogR} | R Documentation |
Length of longest continuous period above/below threshold
Description
This function finds the length of the longest continous period above/below a specified threshold light level or within a specified range of light levels.
Usage
period_above_threshold(
Light.vector,
Time.vector,
comparison = c("above", "below"),
threshold,
epoch = "dominant.epoch",
loop = FALSE,
na.replace = FALSE,
na.rm = FALSE,
as.df = FALSE
)
Arguments
Light.vector |
Numeric vector containing the light data. |
Time.vector |
Vector containing the time data. Can be POSIXct, hms, duration, or difftime. |
comparison |
String specifying whether the period of light levels above or
below threshold should be calculated. Can be either |
threshold |
Single numeric value or two numeric values specifying the threshold light level(s) to compare with. If a vector with two values is provided, the period of light levels within the two thresholds will be calculated. |
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 |
loop |
Logical. Should the data be looped? Defaults to |
na.replace |
Logical. Should missing values (NA) be replaced
for the calculation? If |
na.rm |
Logical. Should missing values (NA) be removed for the calculation?
If |
as.df |
Logical. Should a data frame be returned? If |
Value
A duration object (see duration
) as single value,
or single column data frame.
See Also
Other metrics:
bright_dark_period()
,
centroidLE()
,
disparity_index()
,
duration_above_threshold()
,
exponential_moving_average()
,
frequency_crossing_threshold()
,
interdaily_stability()
,
intradaily_variability()
,
midpointCE()
,
nvRC()
,
nvRD()
,
nvRD_cumulative_response()
,
pulses_above_threshold()
,
threshold_for_duration()
,
timing_above_threshold()
Examples
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))