Hi, I am trying to create a flag for a large database.
There are multiple monthly and if a customer has an outstanding debit for consecutive months, I need a flag "Y". If not then "N" (no flag).
Please see a sample data base:
Name Jan Feb Mar April
a 0 100 150 0
b 100 0 200 0
c 100 100 100 0
Your database seems to be in de-normalised format (not tidy in tidy data speak). I suggest to normalize it as a first step.
Then, assuming there are no gaps in months, it should be a simple case of dplyr::lag().
For normalizing your data (turning it from wide to long format) consider tidyr::pivot_longer().
For an example on dplyr::lag() identifying duplicates (a bit different from your use case - you need both current and previous value >0, but it is a start) consider this post Remove 3rd iteration of duplicate