R/closestToZero.R

Defines functions closestToZero

#' InflectionPoint
#'
#' @param data add description
#' @param timeOrCountVariable add description
#' @param nestingTimeUnit add description
#' @return df dataframe
#' @export
#' 

closestToZero <- function(data,  timeOrCountVariable, nestingTimeUnit) {
  df <- data
  df$time <- y # 'z' arg (specific count variable e.g. countReject) now generic variable
  df$time <- as.numeric(df$time)
  df$nestingUnit <- z
  timeCol <- match('time', names(df))
  nestingUnitCol <- match('nestingUnit', names(df))
  for (i in 1:dim(df)[1]) {
    for (j in 1:dim(df)[2]) {
      if (j == timeCol) {
        if (is.na(df[i, timeCol])) {
          df[i, j] <- -999
        } else {
          if (i != 1) {
            if (df[i, timeCol] >= 0) {
              if (df[(i - 1), timeCol] < 0) {
                df[i, timeCol] <- 0
              }
            }
          }
        }
      }
    }
  }
  ifelse(df$time == -999, NA, df$time)
  df
}
enaY15/MultilevelFunctions documentation built on Aug. 22, 2020, 4:42 p.m.