R/slice.r

Defines functions slice

Documented in slice

#' Function to break up a vector by certain N sized chunks.
#' 
#' @param input Input character vector
#' @param by Number by which to split the input character vector
#' @export 
slice <- function(input, by = 2, equalpiecesof = NULL) {
	if(is.null(equalpiecesof)){	
		starts <- seq(1, length(input), by)
		tt <- lapply(starts, function(y) input[y:(y + (by - 1))])
		lapply(tt, function(x) x[!is.na(x)])
	} else
	{
		splitby <- round(length(input)/equalpiecesof)+1
		starts <- seq(1, length(input), splitby)
		tt <- lapply(starts, function(y) input[y:(y + (splitby - 1))])
		lapply(tt, function(x) x[!is.na(x)])
	}
}
sckott/sacbox documentation built on Sept. 3, 2020, 7:22 p.m.