last {sfsmisc}R Documentation

Get Last Elements of a Vector

Description

Extract the last elements of a vector.

Usage

last(x, length.out = 1, na.rm = FALSE)

Arguments

x

any vector.

length.out

integer indicating how many element are desired. If positive, return the length.out last elements of x; if negative, the last length.out elements are dropped.

na.rm

logical indicating if the last non-missing value (if any) shall be returned. By default (it is FALSE and) the last elements (whatever its values) are returned.

Value

a vector of length abs(length.out) of last values from x.

Note

This function may eventually be deprecated for the new (R 1.9.0) function tail().

Useful for the turnogram() function in package pastecs.

Author(s)

Werner Stahel (stahel@stat.math.ethz.ch), and independently, Philippe Grosjean (phgrosjean@sciviews.org), Frédéric Ibanez (ibanez@obs-vlfr.fr).

See Also

first, turnogram

Examples

a <- c(NA, 1, 2, NA, 3, 4, NA)
last(a)
last(a, na.rm=TRUE)

last(a, length = 2)
last(a, length = -3)

[Package sfsmisc version 1.0-19 Index]