Skip to content
Prev 389113 / 398513 Next

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

Many ways to do this, of course, but if I understand correctly ?rle
may be the simplest, because you already have the data sorted by ID.

The following little example should give you the idea. It gets the
index of the last row in each id,, which you can then use to assign
NA's or whatever:
[1] 1 4 5 6 8

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Thu, Sep 9, 2021 at 12:00 PM Kai Yang via R-help
<r-help at r-project.org> wrote: