I am new to R. I am trying to create a column "Result_2" using values from column "Results". For instance, if an id has 0 for "Results" it gets a 0 in "Result_2" but once it receives 1 in "Results" it stays a 1 in "Results_2" for all the later dates for an id. See Id 1 has 0 results in March so it receives 0 for result_2 but in May it gets 1 results and it receives 1 for both May and June in Results2. My data is sorted by id and date.
Asked
Active
Viewed 20 times
0
-
It's easier to help you if you include your data in a [reproducible format](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) (not in image). – MrFlick Jul 24 '20 at 03:32
-
You can use `cummax` by group. `df$death_ideal <- with(df, ave(Results, Id, FUN = cummax))` – Ronak Shah Jul 24 '20 at 03:33