Get the First or Last Part of an Object

DESCRIPTION:

These functions return either the first (head) or last (tail) parts of a vector, matrix, data frame or function.

USAGE:

head(x, n=6, ...)
tail(x, n=6, ...)

REQUIRED ARGUMENTS:

x
an object.

OPTIONAL ARGUMENTS:

n
an integer. If positive it specifies the number of elements (vector), rows (data frame or matrix) or lines (function) to return from the first or last part of the object. If negative it specifies the number of elements, etc., to omit from the end (head) or beginning (tail) of the object. The default value is 6.
...
arguments passed to methods. These are ignored.

VALUE:

an object of roughly the same type of the input object x if x is not a function. If x is a function, the returned value is a vector of strings that have line numbers at the beginning of each string. If x is an unnamed vector, then tail(x) attaches names of the form [index] to indicate where the entries came from.

DETAILS:

These functions return either the first or last n elements of a vector, rows of a data frame or matrix, or lines of a function. If x is a matrix without row names, then tail will add row names in the form "[n,]" to the return value.

Functions head and tail emulate R functions, but in S-PLUS, the argument addrownums is ignored in the tail function. Also, in S-PLUS (but not R) row names are added to vector values returned by tail.

SEE ALSO:

, , .

EXAMPLES:

head(objects)
head(CO2, n=nrow(CO2)/10)
head(state.x77, n=20)
tail(fuel.frame)
tail(bonds.yield)