R/math-costs.R

Defines functions multi_fun

#' @keywords internal

multi_fun <- function(df, first_pattern, second_pattern, suffix, FUN) {
  p1 = df[stringr::str_detect(names(df), first_pattern)]
  p2 = df[stringr::str_detect(names(df), second_pattern)]
  indices = seq(1:length(p1))
  out = sapply(indices, function (x) {
    return (apply(data.frame(p1[, x], p2[, x]), 1, FUN))
  })
  if (is.vector(out)) {
    out = as.data.frame(t(out))
  } else {
    out = as.data.frame(out)
  }
  names(out) = sapply(names(p1), function(x) gsub(first_pattern, suffix, x))
  return(out)
}
josegallegos07/aceR documentation built on June 27, 2022, 10:25 a.m.