standardize_to_seconds: Standardize location data to fixed time intervals

View source: R/standardize_to_seconds.R

standardize_to_secondsR Documentation

Standardize location data to fixed time intervals

Description

Rounds timestamps to the nearest interval boundary and averages X/Y coordinates if multiple signals fall within the same interval.

Usage

standardize_to_seconds(
  data,
  time_col = "At",
  x_col = "X",
  y_col = "Y",
  id_col = "id_code",
  unit = "second",
  verbose = TRUE
)

Arguments

data

A data frame with location tracking data

time_col

Name of the timestamp column (default: "At")

x_col

Name of x-coordinate column (default: "X")

y_col

Name of y-coordinate column (default: "Y")

id_col

Name of ID column (default: "id_code")

unit

Time interval to standardize to, passed to lubridate::floor_date() (default: "second"). Use "2 seconds", "5 seconds", etc. for coarser intervals.

verbose

Print summary statistics (default: TRUE)

Value

Data frame with one row per (id, interval) with:

  • X, Y: Averaged coordinates

  • n_entries: Number of original signals in that interval

  • standardized: 1 if multiple signals were aggregated, 0 if single

Examples

raw_data <- data.frame(
  id_code = c(1L, 1L, 1L),
  At = as.POSIXct(c("2025-03-18 11:00:00.0", "2025-03-18 11:00:00.5",
                     "2025-03-18 11:00:01.0")),
  X = c(1.0, 1.2, 2.0),
  Y = c(2.0, 2.1, 3.0)
)
standardized_data <- standardize_to_seconds(raw_data)

trackclean documentation built on July 1, 2026, 5:07 p.m.