aggregateEvents: Aggregate Events

View source: R/aggregate_periods.R

aggregateEventsR Documentation

Aggregate Events

Description

Aggregate Events

Usage

aggregateEvents(
  time_series,
  measure = "AGSA",
  time = "timestamp",
  sample_frequency,
  events = NA,
  start_time = "start",
  end_time = "end",
  fun = mean
)

Arguments

time_series

Data frame to be aggregated.

measure

Name of the measure columns to be included.

time

Name of the time column.

sample_frequency

Measurement frequency of data.

events

Data frame containing the start and end index of each event.

start_time

Name of the column in events containing the start index of the events.

end_time

Name of the column in events containing the end index of the events.

fun

Function to apply on aggregation, defaults to mean.

Details

Wrapper function that calls aggregatePeriods for events (duration of variable length).

Value

Data frame of aggregated events.

Examples

timestamp <- c(
  1619424004, 1619424005, 1619424006, 1619424007,
  1619424008, 1619424009, 1619424010, 1619424011,
  1619424012, 1619424013, 1619424014, 1619424015
)
value <- c(
  0.729614366, 1.729115871, 0.804973546, 2.510181118,
  2.23764038, 0.613203747, 0.681953275, 0.089566943,
  0.021042388, 2.4780338, 2.437488989, 2.632635727
)
data <- data.frame(timestamp, value)
event_start <- c(1, 5, 10)
event_end <- c(4, 9, 12)
aggregated_events <- aggregateEvents(data,
  events = data.frame(start = event_start, end = event_end),
  measure = "value",
  time = "timestamp",
  start_time = "start",
  end_time = "end",
  sample_frequency = 1,
  fun = sum
)

GENEAcore documentation built on April 11, 2025, 5:43 p.m.