ct_to_occupancy: Convert camera trap data to occupancy format

View source: R/ct_to_occupancy.R

ct_to_occupancyR Documentation

Convert camera trap data to occupancy format

Description

This function transforms camera trap detection data into an occupancy format suitable for analysis. It aggregates detections into user-defined time windows and optionally converts counts into presence-absence (0/1) data.

Usage

ct_to_occupancy(
  data,
  date_column,
  format = "%Y-%m-%d",
  site_column,
  species_column,
  size_column,
  by_day = 7,
  presence_absence = TRUE
)

Arguments

data

A data frame containing camera trap detection records.

date_column

The name of the column containing detection dates.

format

a character string. If not specified when converting from a character representation, it will try c("%Y-%m-%d", "%Y/%m/%d") one by one, and give an error if none works. Otherwise, the processing is via strptime() whose help page describes available conversion specifications.

site_column

The name of the column identifying sampling sites.

species_column

The name of the column containing species names. Can be NULL if species information is not needed.

size_column

The name of the column representing detection counts.

by_day

An integer specifying the number of days per time window (default: 7).

presence_absence

Logical. If TRUE, converts counts to presence-absence data (1 = detected, 0 = not detected). Default is TRUE.

Value

A wide-format data frame where rows represent sites (and optionally species), and columns represent detection windows. Values indicate either detection counts or presence-absence (0/1).

See Also

ct_to_community()

Examples


data <- data.frame(
  date = c("01-01-2023", "03-01-2023", "10-01-2023", "15-01-2023"),
  site = c("A", "A", "B", "B"),
  species = c("Tiger", "Tiger", "Deer", "Deer"),
  count = c(1, 2, 3, 1)
)

occupancy_data <- ct_to_occupancy(
  data,
  date_column = date,
  site_column = site,
  species_column = species,
  size_column = count,
  by_day = 7,
  presence_absence = TRUE
)

occupancy_data



ct documentation built on Oct. 22, 2026, 1:07 a.m.