Get Last Elements of a Vector
last.RdExtract the last elements of a vector.
Arguments
- x
any vector.
- length.out
integer indicating how many element are desired. If positive, return the
length.outlast elements ofx; if negative, the lastlength.outelements are dropped.- na.rm
logical indicating if the last non-missing value (if any) shall be returned. By default (it is
FALSEand) the last elements (whatever its values) are returned.
Author
Werner Stahel ([email protected]), and independently, Philippe Grosjean ([email protected]), Frédéric Ibanez ([email protected]).
Note
This function may eventually be deprecated for the standard R
function tail().
Useful for the turnogram() function in package
pastecs.
Examples
a <- c(NA, 1, 2, NA, 3, 4, NA)
last(a)
#> [1] NA
last(a, na.rm=TRUE)
#> [1] 4
last(a, length = 2)
#> [1] 4 NA
last(a, length = -3)
#> [1] NA 1 2 NA