R/recycle.R

Defines functions recycle

Documented in recycle

# recycle.R
# ::rtemis::
# E.D. Gennatas www.lambdamd.org

#' Recycle values of vector to match length of target
#' 
#' @param x Vector to be recycled
#' @param target Object whose length defines target length
#'
#' @author E.D. Gennatas
#' @export

recycle <- function(x, target) {

  lenx <- length(x)
  lent <- length(target)

  if (lenx >= lent) {
    x
  } else {
    rep(x, ceiling(lent/lenx))[seq(lent)]
  }

} # rtemis::recycle
egenn/rtemis documentation built on May 4, 2024, 7:40 p.m.