last: Last Elements of a Vector or of a Matrix

Description Usage Arguments Value Note Author(s) Examples

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

1

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

1
2
3
4
5
6
  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)

regr0 documentation built on May 2, 2019, 4:52 p.m.