resample: Resample a time series to a calendar grid

View source: R/resample.R

resampleR Documentation

Resample a time series to a calendar grid

Description

Buckets a datetime column to a grid (every) and aggregates within each bucket – the time-series form of group_by() + summarise(). Equivalent to ⁠mutate(<time> = floor_time(<time>, every))⁠, ⁠group_by(<time>)⁠, then summarise(...).

Usage

resample(.data, time, every, ..., .name = NULL)

Arguments

.data

A vectra_node.

time

The datetime column to bucket (unquoted).

every

Bucket size as a string, e.g. "1 hour", "15 min", "day", "month" (see floor_time()).

...

Named aggregation expressions, as in summarise() (e.g. mean_temp = mean(temp)).

.name

Optional name for the bucket column. Defaults to the name of time (the original column, replaced by its floored value).

Value

A vectra_node with one row per occupied bucket: the bucket column followed by the aggregates. The bucket collects as a numeric epoch value (see floor_time() on restoring the date class).

See Also

floor_time(), summarise()

Examples

## Not run: 
tbl("readings.vtr") |>
  resample(timestamp, "1 hour", mean_temp = mean(temp), n = n()) |>
  collect()

## End(Not run)


vectra documentation built on July 10, 2026, 5:08 p.m.