R/every_nth.r

Defines functions every_nth

Documented in every_nth every_nth

#' every_nth
#'
#' For removing parts of sequences
#' @param x the sequence
#' @param nth keep every nth item, remove everything else
#' @param empty if the removed items should leave an empty space behind
#' @param inverse invert the function, and keep nth items instead of removing them
#' @export
#' @examples
#' every_nth()

every_nth <- function(x, nth, empty = TRUE, inverse = TRUE) {
  # Source: User Maninal at Stackoverflow
  if (!inverse) {
    if(empty) {
      x[1:nth == 1] <- ""
      x
    }
    else {
      x[1:nth != 1]
    }
  }
  else {
    if(empty) {
      x[1:nth != 1] <- ""
      x
    }
    else {
      x[1:nth == 1]
    }
  }
}
Eiriksen/Eiriksens-testomatix documentation built on Oct. 30, 2019, 5:31 p.m.