Hi, x<-1:80 y<- x[-(1:77)] y
#[1] 78 79 80 #or ?tail() #already suggested If you want only the last element,, library(pastecs) last(x) #[1] 80 A.K. ----- Original Message ----- From: hp wan <huaping....@gmail.com> To: r-help@r-project.org Cc: Sent: Thursday, January 24, 2013 7:23 PM Subject: [R] How to extract elements from vector in reverse order? 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) ? In Matlab, It can easily achieve by y=x(end-2:end) Thanks Huaping Wan [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.