Feature engineering: 'if yesterday exists, set lead variable = 1' + 'if tomorrow exists, set lag variable = 1'

Scenario:
Let's say x = 1 on 2000 Jan 15.
So calendar_date column with 2000-01-15 value

Expected result:
Then x_lead := 1 on 2000 Jan 14
and x_lag := 1 on 2000 Jan 16


First, how do I detect that 2000-01-14 exists in the calendar_date column?
Then, how would I df |> mutate(x_lead = 1) at the 2000-01-14 row?

Use case_when, with condition being absolute of date difference being 1.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.