I have a column of pdf values and a conditional column. I am attempting to create a third column that forward fills in values from the pdf column based on the conditional column. If the condition is TRUE
then I would like the corresponding row to restart the pdf column from the beginning.
I've seen this question posted R: fill new columns in data.frame based on row values by condition? and it is close but I would like a dplyr solution to retain my pipe structure.
Very Simple Example Data:
library(tidyverse)
dat <- tibble(pdf = c(.025, .05, .10, .15, .175, .20, .29, .01),
cond = c(F, F, T, F, F, F, T, F),
expected = c(.025, .05, .025, .05, .10, .15, .025, .05))
The expected is seen in the dataframe above. (Note that I don't see the expected
column)
Thank you in advance.