Skip to contents

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,
  metric,
  Variable,
  Weekend.type = Day,
  Datetime.colname = Datetime,
  metric_type = duration_above_threshold,
  prefix = "average_",
  filter.empty = FALSE,
  ...
)

Arguments

data

A dataframe containing light logger data imported with LightLogR

metric

The name of the metric column to create in the output. Expects a character

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

...

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

# Import sample data
filepath <- system.file("extdata/sample_data_LYS.csv", package = "LightLogR")
dataset <- import$LYS(filepath, silent = TRUE)

# Calculate mean daily duration above threshold. As the data only contains
# data for two days, Weekend and Mean daily will throw NA
dataset |> 
mean_daily_metric(
  metric = "duration_above_100lux",
  Variable = lux,
  threshold = 100
)
#> # A tibble: 3 × 3
#> # Groups:   Id [1]
#>   Id              Day        average_duration_above_100lux
#>   <fct>           <chr>      <Duration>                   
#> 1 sample_data_LYS Mean daily NA                           
#> 2 sample_data_LYS Weekday    16935s (~4.7 hours)          
#> 3 sample_data_LYS Weekend    NA                           

# again with another dataset
sample.data.environment |> 
  mean_daily_metric(
  metric = "duration_above_250lux",
  Variable = MEDI,
  threshold = 250)
#> # A tibble: 6 × 3
#> # Groups:   Id [2]
#>   Id          Day        average_duration_above_250lux
#>   <fct>       <chr>      <Duration>                   
#> 1 Environment Mean daily 48710s (~13.53 hours)        
#> 2 Environment Weekday    48712s (~13.53 hours)        
#> 3 Environment Weekend    48705s (~13.53 hours)        
#> 4 Participant Mean daily 15716s (~4.37 hours)         
#> 5 Participant Weekday    11495s (~3.19 hours)         
#> 6 Participant Weekend    26270s (~7.3 hours)