R equivalent of .first or .last sas operator

Posted by Giorgio Spedicato on Stack Overflow See other posts from Stack Overflow or by Giorgio Spedicato
Published on 2012-12-07T15:03:38Z Indexed on 2012/12/09 17:04 UTC
Read the original article Hit count: 397

Filed under:
|

Does anybody know what is the best R alternative to SAS first. or last. operators? I did find none.

SAS has the FIRST. and LAST. automatic variables, which identify the first and last record amongst a group with the same value with a particular variable; so in the following dataset FIRST.model and LAST.model are defined:

Model,SaleID,First.Model,Last.Model
Explorer,1,1,0
Explorer,2,0,0
Explorer,3,0,0
Explorer,4,0,1
Civic,5,1,0
Civic,6,0,0
Civic,7,0,1

© Stack Overflow or respective owner

Related posts about r

    Related posts about sas