\HeaderA{head}{Return the First or Last Part of an Object}{head}
\methaliasA{head.data.frame}{head}{head.data.frame}
\methaliasA{head.default}{head}{head.default}
\methaliasA{head.ftable}{head}{head.ftable}
\methaliasA{head.function}{head}{head.function}
\methaliasA{head.matrix}{head}{head.matrix}
\methaliasA{head.table}{head}{head.table}
\aliasA{tail}{head}{tail}
\methaliasA{tail.data.frame}{head}{tail.data.frame}
\methaliasA{tail.default}{head}{tail.default}
\methaliasA{tail.ftable}{head}{tail.ftable}
\methaliasA{tail.function}{head}{tail.function}
\methaliasA{tail.matrix}{head}{tail.matrix}
\methaliasA{tail.table}{head}{tail.table}
\keyword{manip}{head}
\begin{Description}\relax
Returns the first or last parts of a vector, matrix, table, data frame
or function.  Since \code{head()} and \code{tail()} are generic
functions, they may also have been extended to other classes.
\end{Description}
\begin{Usage}
\begin{verbatim}
head(x, ...)
## Default S3 method:
head(x, n = 6, ...)
## S3 method for class 'data.frame':
head(x, n = 6, ...)
## S3 method for class 'matrix':
head(x, n = 6, ...)
## S3 method for class 'ftable':
head(x, n = 6, ...)
## S3 method for class 'table':
head(x, n = 6, ...)
## S3 method for class 'function':
head(x, n = 6, ...)

tail(x, ...)
## Default S3 method:
tail(x, n = 6, ...)
## S3 method for class 'data.frame':
tail(x, n = 6, ...)
## S3 method for class 'matrix':
tail(x, n = 6, addrownums = TRUE, ...)
## S3 method for class 'ftable':
tail(x, n = 6, addrownums = FALSE, ...)
## S3 method for class 'table':
tail(x, n = 6, addrownums = TRUE, ...)
## S3 method for class 'function':
tail(x, n = 6, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] an object
\item[\code{n}] a single integer. If positive, size for the resulting
object: number of elements for a vector (including lists), rows for
a matrix or data frame or lines for a function. If negative, all but
the \code{n} last/first number of elements of \code{x}.
\item[\code{addrownums}] if there are no row names, create them from the row
numbers.
\item[\code{...}] arguments to be passed to or from other methods.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
For matrices, 2-dim tables and data frames, \code{head()} (\code{tail()}) returns
the first (last) \code{n} rows when \code{n > 0} or all but the
last (first) \code{n} rows when \code{n < 0}.  \code{head.matrix()} and
\code{tail.matrix()} are exported.  For functions, the
lines of the deparsed function are returned as character strings.

If a matrix has no row names, then \code{tail()} will add row names of
the form \code{"[n,]"} to the result, so that it looks similar to the
last lines of \code{x} when printed.  Setting \code{addrownums =
    FALSE} suppresses this behaviour.
\end{Details}
\begin{Value}
An object (usually) like \code{x} but generally smaller.  For
\code{\LinkA{ftable}{ftable}} objects \code{x}, a transformed \code{format(x)}.
\end{Value}
\begin{Author}\relax
Patrick Burns, improved and corrected by R-Core. Negative argument
added by Vincent Goulet.
\end{Author}
\begin{Examples}
\begin{ExampleCode}
head(letters)
head(letters, n = -6)

head(freeny.x, n = 10)
head(freeny.y)

tail(letters)
tail(letters, n = -6)

tail(freeny.x)
tail(freeny.y)

tail(library)

head(stats::ftable(Titanic))
\end{ExampleCode}
\end{Examples}

