R: Last item of an object

last {data.table} | R Documentation

## Last item of an object

### Description

Returns the last item of a vector or list, or the last row of a data.frame or data.table.

### Usage

    last(x, ...)

### Arguments

`x` | A vector, list, data.frame or data.table. Otherwise the S3 method of `xts::last` is deployed.
`...` | Not applicable for `data.table::last`. Any arguments here are passed through to `xts::last`.

### Value

If no other arguments are supplied it depends on the type of x. The last item of a vector or list. The last row of a `data.frame` or `data.table`. Otherwise, whatever `xts::last` returns (if package xts has been loaded, otherwise a helpful error).

If any argument is supplied in addition to `x` (such as `n` or `keep` in `xts::last`), regardless of `x`'s type, then `xts::last` is called if xts has been loaded, otherwise a helpful error.

### See Also

`NROW`, `head`, `tail`, `first`

### Examples

    last(1:5) # [1] 5
    x = data.table(x=1:5, y=6:10)
    last(x) # same as x[5]

[Package data.table version 1.11.8 Index]