fix_tag_replacement: Fix tag replacements in raw data

View source: R/fix_tag_replacement.R

fix_tag_replacementR Documentation

Fix tag replacements in raw data

Description

Handles cases where a participant's tracking tag was replaced during data collection. Renames observations from the new tag to the original ID and removes invalid observations.

Usage

fix_tag_replacement(
  data,
  original_id,
  replacement_id,
  replacement_time,
  time_col = "At",
  id_col = "ID"
)

Arguments

data

A data frame with raw tracking data

original_id

The participant's original tag ID

replacement_id

The new tag ID that replaced the original

replacement_time

Time when tag was replaced (POSIXct or character, e.g. "2025-03-18 11:20:00")

time_col

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

id_col

Name of the ID column (default: "ID")

Value

Data frame with corrected IDs:

  • Observations from replacement_id >= replacement_time are renamed to original_id

  • Observations from original_id >= replacement_time are removed

  • Observations from replacement_id < replacement_time are removed

Examples

raw_data <- data.frame(
  ID = c(159L, 159L, 106L, 106L),
  At = as.POSIXct(c("2025-03-18 11:00:00", "2025-03-18 11:30:00",
                     "2025-03-18 11:00:00", "2025-03-18 11:30:00")),
  X  = c(1.0, 2.0, 3.0, 4.0),
  Y  = c(1.0, 2.0, 3.0, 4.0)
)
raw_data <- fix_tag_replacement(
  data = raw_data,
  original_id = 159,
  replacement_id = 106,
  replacement_time = "2025-03-18 11:20:00"
)

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