mean_daily_metric: Calculate mean daily metrics from Time Series

View source: R/mean_daily.R

mean_daily_metricR Documentation

Calculate mean daily metrics from Time Series

Description

mean_daily_metric is a convenience wrapper around mean_daily that summarizes data imported with LightLogR per weekday and calculates mean daily values for a specific metric. Examples include duration_above_threshold() (the default), or durations().

Usage

mean_daily_metric(
  data,
  Variable,
  Weekend.type = Date,
  Datetime.colname = Datetime,
  metric_type = duration_above_threshold,
  prefix = "average_",
  filter.empty = FALSE,
  Datetime2Time = TRUE,
  ...
)

Arguments

data

A dataframe containing light logger data imported with LightLogR

Variable

The variable column to analyze. Expects a symbol. Needs to be part of the dataset.

Weekend.type

A (new) column in the dataframe that specifies the day of the week as a factor

Datetime.colname

Column name containing datetime values. Defaults to Datetime

metric_type

The metric function to apply, default is duration_above_threshold()

prefix

String that is the prefix on summarized values

filter.empty

Filter out empty rows. Default is FALSE

Datetime2Time

Logical of whether POSIXct columns should be transformed into hms(time) columns, which is usually sensible for averaging (default is TRUE). Calls Datetime2Time() with default settings (all POSIXct are affected).

...

Additional arguments passed to the metric function

Value

A dataframe with three rows representing average weekday, weekend, and mean daily values for the specified metric

Examples


# Calculate mean daily duration above threshold. As the data only contains
# data for two days, Weekend and Mean daily will throw NA
sample.data.irregular |> 
aggregate_Datetime(unit = "1 min") |> 
mean_daily_metric(
  Variable = lux,
  threshold = 100
)

# again with another dataset
sample.data.environment |> 
  mean_daily_metric(
  Variable = MEDI,
  threshold = 250)

# by default, datetime columns are converted to time
sample.data.environment |> 
  mean_daily_metric(
  Variable = MEDI,
  metric_type = timing_above_threshold,
  threshold = 250)


LightLogR documentation built on June 10, 2025, 5:12 p.m.