[R] select the last row by id group

Tony Chu gatony at gmail.com
Mon Jun 12 19:34:33 CEST 2006


  Dear R users:

  I have a small test dataframe as the follows :

math = c(80,75,70,65,65,70)
reading = c(65,70,88,NA,90,NA)
id = c('001','001','001','002','003','003')
score = data.frame(id, reading, math)

> score
   id reading math
1 001      65   80
2 001      70   75
3 001      88   70
4 002      NA   65
5 003      90    65
6 003      NA   70

  Could someone advise me tips about how to select the last row from
each id group of 001, 002, & 003?

In other words, the rows I need are :

   id reading math
3 001      88   70
4 002      NA   65
6 003      NA   70

 I tried function sebset but could not go very far. Thanks !



More information about the R-help mailing list