Let's suppose I have this dataframe:
Date A B
2010-01-01 NA 1
2010-01-02 2 NA
2010-01-05 3 NA
2010-01-07 NA 4
2010-01-20 5 NA
2010-01-25 6 7
I want to collapse rows, removing the NA values to the closest Date. So the result would be:
Date A B
2010-01-02 2 1
2010-01-07 3 4
2010-01-20 5 NA
2010-01-25 6 7
I saw this stack overflow that solves collapsing using a key value, but I could not find a similar case using close date values to collapse.
Obs1: It would be good if there was a way to not collapse the rows if the dates are too far apart (example: more than 15 days apart).
Obs2: It would be good if the collapsing lines kept the latter date rather than the earlier, as shown in the example above.