first: Return first or last element of an object

Description Usage Arguments Value Author(s) See Also Examples

Description

Return first or last element of an object. These functions are convenience wrappers for head(x, n=1, ...) and tail(x, n=1, ...).

Usage

1
2
first(x, n=1, ...)
last(x, n=1, ...)

Arguments

x

data object

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 'n' last/first number of elements of 'x'.

...

arguments to be passed to or from other methods.

Value

An object (usually) like 'x' but generally smaller.

Author(s)

Gregory R. Warnes greg@warnes.net

See Also

head, tail, left, right

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## works for vectors..
v <- 1:10
first(v)
last(v)

## and for lists
l <- list(a=1, b=2, c=3)
first(l)
last(l)

## and data.frames
df <- data.frame(a=1:2, b=3:4, c=5:6)
first(df)
last(df)

## and matrixes
m <- as.matrix(df)
first(m)
last(m)


Search within the gdata package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.