lastn | R Documentation |
Extract the last n elements of a vector
lastn(x, n)
x |
a vector |
n |
number of elements to keep, an integer |
I did not know about the function tail()
when I did this one,
but the two functions are not completely equivalent (and tail
is generic).
If n
is equal to length(x)
, x
is returned as is.
If n
is equal to zero or is negative, a length zero vector is
returned.
It is an error for n
to be larger than length(x)
.
a vector containing the last n
elements of x
,
see Details
See Also as tail
lastn(1:10, 3) # 8:10
lastn(letters, 5) # "v" "w" "x" "y" "z"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.