[R] Select the last two rows by id group

Christos Hatzis christos at nuverabio.com
Tue Mar 20 16:10:39 CET 2007


You can try the following:

n.len <- nrow(iris)
n.sel <- 3

iris[(n.len-n.sel+1):n.len, ]

-Christos 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Lauri Nikkinen
> Sent: Tuesday, March 20, 2007 10:33 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Select the last two rows by id group
> 
> Hi R-users,
> 
> Following this post 
> http://tolstoy.newcastle.edu.au/R/help/06/06/28965.html , how 
> do I get last two rows (or six or ten) by id group out of the 
> data frame? Here the example gives just the last row.
> 
> Sincere thanks,
> Lauri
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
> 
>



More information about the R-help mailing list