[R] How to extract elements from vector in reverse order?

David Winsemius dwinsemius at comcast.net
Fri Jan 25 02:53:44 CET 2013


On Jan 24, 2013, at 4:23 PM, hp wan wrote:

> Hi all mailing listers,
> 
> I wanna get the last several elments of vector.
> e.g.  x <- c(1,2,3,.....,78, 79, 80)
> 
> How can I implement to assign last three elements to y,  y <- c(78, 79, 80)
> ?

?tail

> In Matlab, It can easily achieve by y=x(end-2:end)

y <- tail(x, 3)

-- 
David Winsemius
Alameda, CA, USA



More information about the R-help mailing list