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
It sounds like you’re looking for
!duplicated, with thefromLastargument beingFALSEorTRUE.There are some caveats and edge-case behaviors to this function, which you can find out through the help files (
?duplicated).