You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now add a column z, based on column x, that starts from 1 and retains the same value (or group) as long as the successive values are the same. That is, in this case, z is:
I've seen this scenario come across quite a few times on SO:
Now add a column
z
, based on columnx
, that starts from1
and retains the same value (or group) as long as the successive values are the same. That is, in this case,z
is:This can be accomplished quite easily with
data.table
's internal utility functionsuniqlist
anduniqlengths
. Here's a preliminary illustration:So, the usage would be typically:
Here's a SO post and another.
The text was updated successfully, but these errors were encountered: