head
Get the First or Last Part of an Object
Description
Returns either the first (head) or last (tail) parts of a vector,
matrix, data frame, table or function.
Usage
head(x, ...)
tail(x, ...)
Arguments
x |
an object.
|
... |
additional arguments passed to the head or tail method.
|
Details
head and
tail return (respectively) 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 or a table,
tail accepts an additional argument addrownums, with the
default TRUE.
- If x is a matrix or a table without row names, and addrownums is
TRUE, tail adds row names in the form "[n,]" to the
return value.
Additional arguments can include an integer,
n, specifying
the following:
- 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.
Value
returns 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.
See Also
Examples
head(objects())
head(matrix(1:16,4), n=2)
head(data.frame(x=1:10,y=101:110), n=-3)
tail(matrix(1:16,4), n=2)
tail(data.frame(x=1:10,y=101:110), n=-3)