My dataframe looks like this
df <- read.table(text=" id nr date 1 124 1 2017-01-01 2 122 1 2017-01-03 3 124 2 2017-01-04 4 121 1 2017-02-05 5 124 3 2017-02-06 6 124 3 2017-04-06 ", header=TRUE)
I have to remove rows from my dataframe where difference in days is less than 30 days. I usually do it with lead function, then I calculate difference in days and if it's below the limit then I remove it.
But now I want to remove each row that is below the limit. And not just that; if its date difference between date more than 30 days, then I have to filter all next rows that are below the limit.
In other words, there is first row, row numbers 2 and 3 should be removed, since date difference is only a few days. Difference between row 4 and one is more than 30 days, so it shouldn't be removed, difference between row 4 and 5 is less than 30 days so remove it, 6 should be present in result since difference is more than 30 days and so on.