R/count_between.R

Defines functions count_between

Documented in count_between

#' @title Count between
#' @name count_between
#' @description Function to quantify temperature hours between x and y.
#' @param tli lower limit
#' @param tls upper limit
#' @param x Vector containing values (data).
#' @param total TRUE Shows the total value of hours.
#' @details Function to quantify temperature hours between x and y.
#' @return The function returns the total value of hours.
#' @examples 
#' 
#' x <- rnorm(500, 7, 3)
#' 
#' count_between(tli = 8, tls = 15, x = x,  total = TRUE)
#' 
#' @importFrom utils tail
#' @export

count_between <- function(tli,tls, x, total=TRUE){
  y <- rep(0, length(x))
  y[which(x>=tli & x<tls)] <- 1
  if (total==TRUE)
    return(tail(cumsum(y),n=1))
  else return(y)
}

Try the ChillModels package in your browser

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

ChillModels documentation built on March 26, 2020, 6:28 p.m.