I have a Dataframe with a date column and an outcome column (1 or 0):
df <- data.frame(matrix(nrow=100,ncol = 2))
colnames(df) <- c("date_1", "var")
df$date_1 <- sample(seq(as.Date('1999/01/01'), as.Date('2000/01/01'), by="day"), 100)
df$var <- rbinom(100, 1, 0.2)
I want to make a new variable (preferably using mutate/dplyr) called "date_2" that assigns the date from the "date_1" variable but only if var==1?