R/interleave_results.R

Defines functions interleave_results

Documented in interleave_results

#' Helper for reading interleaving prelims and finals results
#'
#' Interleaves times or places based on row number ranges.
#'
#' @param entries a data frame containing columns for minimum and maximum row
#'   number (usually `Row_Min` and `Row_Max`).  Times or places will be
#'   interleaved into this data frame.
#' @param results a data frame containing times (or places) in column 1 (or
#'   other values to be interleaved) and row numbers in column 2 (usually
#'   `Row_Numb`).
#' @param type either "individual" or "relay"
#' @return a modified version of `entries` with values from `results`
#'   interleaved on the basis of row number
#'
#' @seealso \code{interleave_results} is a helper function used in
#'   \code{\link{hy3_parse}}

interleave_results <-
  function(entries,
           results,
           type = c("individual", "relay")) {

    if (type == "individual") {
      # Adding in results
      i <- cut(results$Row_Numb, t(entries[, 6:7]))
      levels(i)[c(FALSE, TRUE)] <- NA
      entries[[names(results[1])]][i] <- results[[1]]
    } else if (type == "relay") {
      # relays
      i <- cut(results$Row_Numb, t(entries[, 5:6]))
      levels(i)[c(FALSE, TRUE)] <- NA
      entries[[names(results[1])]][i] <- results[[1]]
    }
    return(entries)
  }

Try the SwimmeR package in your browser

Any scripts or data that you put into this service are public.

SwimmeR documentation built on March 31, 2023, 8:27 p.m.