I'd need a function that checks my data frame for an otherwise identical row, but with date minus 1, and returns true
if it exists. It's a large data frame, so I'd like to do it as efficiently as possible.
For example, take the following data frame:
name |date
Timmy |01/Jan/2016
Timmy |02/Jan/2016
Timmy |03/Jan/2016
Sally |04/Jan/2016
Johnny|13/Feb/2016
Johnny|29/Mar/2016
The function should see Timmy|02/Jan/2016
, check if Timmy|01/Jan/2016
exists, and return true
. The resulting data frame would look like this:
name |date |hasDateMinusOne
Timmy |01/Jan/2016|false
Timmy |02/Jan/2016|true
Timmy |03/Jan/2016|true
Sally |04/Jan/2016|false
Johnny|13/Feb/2016|false
Johnny|29/Mar/2016|false
This is the closest answer I've found. Although it was answered by Hadley, it's 5 years old and predates dplyr. I'm wondering if it's still the most efficient way to handle 1,000,000+ rows.
Thanks!
Sean