Skip to content
Prev 389120 / 398513 Next

how to find "first" or "last" record after sort in R

Thanks Therneau,?duplicated() function works well. --- Kai
On Friday, September 10, 2021, 05:13:47 AM PDT, Therneau, Terry M., Ph.D. <therneau at mayo.edu> wrote:
I prefer the duplicated() function, since the final code will be clear to a future reader. 
? (Particularly when I am that future reader).

last <- !duplicated(mydata$ID, fromLast=TRUE)? # point to the last ID for each subject
mydata$data3[last] <- NA

Terry T.

(I read the list once a day in digest form, so am always a late reply.)
On 9/10/21 5:00 AM, r-help-request at r-project.org wrote: