R/decider.R

Defines functions decider

Documented in decider

#' Decider
#'
#' A helper function. Highlights which double interactions to keep or exclude. Used inside "get_int_decision".
#'
#' @param x A data frame of interactions. Typically generated by the "duration decider" function. Needs columns "focal_dyad_count" and "partner_dyad_count". (created by get_p_dyad_count).
#'
#' @return Adds new "double_interaction" column with decision on wether to "include" or "exclude" a particular interaction event.
#' @export

decider <- function(x) {
  # create new empty column to fill with decision
  x$double_interaction <- NA

  # fill in double interaction column  w/ "include", "exclude"
  for (i in seq_len(nrow(x))){
    # if focal and action_partner have the same dyad count for a particular date
    if(x$focal_dyad_count[[i]] == x$partner_dyad_count[[i]]){
      # then call decider_same_count function to choose whether to include or exclude this double interaction
      x$double_interaction[[i]] <-
        decider_same_count(x$focal_animal[[i]], x$action_partner[[i]])
    } else {
      # else focal and action_partner DO NOT have the same dyad count for a particular date
      # then call decider_diff_count function to choose whether to include or exclude this double interaction
      x$double_interaction[[i]] <-
        decider_diff_count(x$focal_dyad_count[[i]], x$partner_dyad_count[[i]])
    }
  }
  return(x)
}
avrincon/phdfuns documentation built on Nov. 13, 2022, 10:34 a.m.