last: Last Elements of a Vector or of a Matrix

lastR Documentation

Last Elements of a Vector or of a Matrix

Description

Selects or drops the last element or the last n elements of a vector or the last n rows or ncol columns of a matrix

Usage

last(data, n = NULL, ncol=NULL, drop=is.matrix(data))

Arguments

data

vector or matrix or data.frame from which to select or drop

n

if >0, last selects the last n elements (rows) form the result.
if <0, the last abs(n) elements (rows) are dropped, and the first length(data)-abs(n) ones from the result

ncol

if data is a matrix or data.frame, the last ncol columns are selected (if ncol is positive) or dropped (if negative).

drop

if only one row or column of a matrix (or one column of a data.frame) is selected or left over, should the result be a vector or a row or column matrix (or one variable data.frame)

Value

The selected elements of the vector or matrix or data.frame

Note

This is a very simple function. It is defined mainly for selecting from the results of other functions without storing them.

Author(s)

Werner Stahel

Examples

  x <- runif(rpois(1,10))
  last(sort(x), 3)
  last(sort(x), -5)
##
  df <- data.frame(X=c(2,5,3,8), F=LETTERS[1:4], G=c(TRUE,FALSE,FALSE,TRUE))
  last(df,3,-2)

relevance documentation built on Aug. 24, 2023, 3:03 p.m.