
Analyze Within-Meal Actor/Reactor Roles
Source:R/meal_replacement_roles.R
meal_replacement_roles.RdAnalyzes the percentage of visits within each meal where an animal entered as an actor (replaced another animal) or left as a reactor (was replaced by another animal). Returns meal-level detail showing role percentages.
Usage
meal_replacement_roles(
visit_data,
replacement_data,
time_tolerance = 1,
id_col = id_col2(),
bin_col = bin_col2(),
start_col = start_col2(),
end_col = end_col2()
)Arguments
- visit_data
A named list of daily data frames or a single data frame containing visit records with meal labels.
- replacement_data
A named list of daily data frames or a single data frame containing replacement events from
record_replacement_days().- time_tolerance
Numeric. Time tolerance in seconds for matching visits to replacement events. Default is 1 second.
- id_col
Animal ID column name (default current global value from
id_col2())- bin_col
Bin ID column name (default current global value from
bin_col2())- start_col
Start time column name (default current global value from
start_col2())- end_col
End time column name (default current global value from
end_col2())
Value
A data frame (or named list of data frames) with columns:
date- Date[id_col]- Animal identifiermeal_id- Meal identifiertotal_visits_in_meal- Total visits in the mealactor_visits- Number of visits where animal entered as actorreactor_visits- Number of visits where animal left as reactoractor_reactor_visits- Number of visits with both rolespct_actor- Percentage of visits as actorpct_reactor- Percentage of visits as reactorpct_actor_reactor- Percentage of visits with both roles
Examples
# Create sample visit data with meal labels
visits <- data.frame(
date = "2024-01-01",
cow = c("A", "A", "B", "B"),
bin = c(1, 2, 1, 2),
start = as.POSIXct(c(
"2024-01-01 08:00:00",
"2024-01-01 08:15:00",
"2024-01-01 08:10:00",
"2024-01-01 08:20:00"
), tz = "UTC"),
end = as.POSIXct(c(
"2024-01-01 08:10:00",
"2024-01-01 08:20:00",
"2024-01-01 08:15:00",
"2024-01-01 08:25:00"
), tz = "UTC"),
meal_id = c(1, 1, 1, 1),
meal_start = as.POSIXct("2024-01-01 08:00:00", tz = "UTC")
)
# Create replacement data
replacements <- data.frame(
actor_cow = "B",
reactor_cow = "A",
bin = 1,
time = as.POSIXct("2024-01-01 08:10:00", tz = "UTC")
)
# Analyze actor/reactor roles within meals
meal_roles <- meal_replacement_roles(
visit_data = visits,
replacement_data = replacements
)