R/slices.R

Defines functions slices slices.default slices.list slices.matrix slices.data.frame

Documented in slices

#' Display slices of the object
#' 
#' Returns n elements of the object taken in even intervals.
#' 
#' @param x object
#' @param n a single integer. Size for the resulting object:
#'          number of elements for a vector (including lists),
#'          rows for a matrix or data frame.
#' 
#' @export

slices <- function(x, n = 6L) UseMethod("slices")


#' @export

slices.default <- function(x, n = 6L) {
   x[seq(1, length(x), length.out = n)]
}


#' @export

slices.list <- function(x, n = 6L) {
   x[seq(1, length(x), length.out = n)]
}


#' @export

slices.matrix <- function(x, n = 6L) {
   x[seq(1, nrow(x), length.out = n), ]
}


#' @export

slices.data.frame <- function(x, n = 6L) {
   x[seq(1, nrow(x), length.out = n), ]
}
twolodzko/twextras documentation built on May 3, 2019, 1:52 p.m.