#' 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]
}
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.