A
A
Ashot Ogoltsov2016-03-07 23:45:51
R
Ashot Ogoltsov, 2016-03-07 23:45:51

Streak or No Streak?

All the best,
Question on the R language (probably). There are many lines of text like the client ID and date.
Client IDs are repeated, maybe twice in one day. How to count streaks?
A streak is when the client ID is repeated from day to day, say the day before yesterday and yesterday it is a double streak, and the day before yesterday, yesterday and today it is a triple streak. At the same time, from February 1 to February 11 and from February 13 to February 15, these are two streaks, one for 10 days and one for days, the maximum streak is of interest.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mindlin, 2016-03-08
@kgbplus


max(rle( as.character (data[data["id"]==1,"date"]))) the proposal is:
1. Select all dates by one ID
2. Do rle() on a column with dates, it will reveal consecutive chains and their lengths
3. Find the maximum

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question