R/horse_acc.R

Defines functions horse_acc

Documented in horse_acc

#' Horse Acceleration
#'
#' This function calculates the radial acceleration in meters per squaresecond
#' from gps velocity (filtered) for multiple rides in the same dataframe
#' The dataframe "data" has to be structured as follows:
#' col "ID" with horse identifier, col "Zeit" with timestamp (tz = "Europe/Berlin"),
#' col "Delta_t" with time difference in seconds,
#' col "V_gefiltert" with filtered velocity in meters per minute

#' @export
horse_acc <- function(data) {
  data <- data %>% dplyr::mutate(Datum = as.Date(Zeit, tz = "Europe/Berlin"))
  data <- data %>% dplyr::group_by(ID, Datum) %>% tidyr::nest()
  data <- data %>% dplyr::mutate(Delta_V = purrr::map(data, ~as.numeric(tsibble::difference(.x$V_gefiltert))))
  data <- tidyr::unnest(data, cols = c(data, Delta_V))
  data <- dplyr::ungroup(data)
  data <- data %>%
    dplyr::mutate(Acceleration = ifelse(Delta_t != 0, (Delta_V/60)/Delta_t, 0))
  data <- data %>% dplyr::select(-Delta_V)
}
KatiKirsch/horses documentation built on April 25, 2022, 4:55 p.m.