[R] Select the last two rows by id group

Christian Ritz ritz at kvl.dk
Tue Mar 20 16:06:26 CET 2007


Hi Lauri,

here is a little modification of the solution for retrieving the last 
row only :


score[as.vector(unlist(tapply(rownames(score), score$id, tail, 2))),]


giving the last two rows. Replacing 2 by 6 or 10 gives you the last 6 
or 10 rows (if they exist).


Christian



More information about the R-help mailing list