"tail" <- function(x, ...) UseMethod('tail') "tail.default" <- function(x, n=6) { # placed in the public domain 2002 # Patrick Burns patrick@burns-stat.com if(is.matrix(x)) return(tail.data.frame(x, n=n)) if(is.function(x)) return(Recall(deparse(x), n=n)) xlen <- length(x) n <- min(n, xlen) ans <- x[seq(to=xlen, length=n)] if(length(dim(x)) == 1) array(ans, n, list(names(ans))) else ans } "tail.data.frame" <- function(x, n=6) { # placed in the public domain 2002 # Patrick Burns patrick@burns-stat.com nrx <- nrow(x) n <- min(n, nrx) x[seq(to=nrx, length=n),,drop=FALSE] }