Assume I have a list that contains either 0 or 1.
Next to this one (call it ColA), I want to add a column (call it ColB) which takes the following values:
i. if ColA == 1, then the next n rows in ColB should be flagged with 1
ii. if ColA == 0, then the corresponding row in ColB should be flagged with 0 unless it is one of those n rows subsequent a 1 in ColA
Can anyone suggest a sketch of code/an idea of how to achieve this?
Any solution in R, SQL, Python or C++ is appreciated.
Aucun commentaire:
Enregistrer un commentaire