I wish to write a loop which removes all values from each year column, one at a time, if the value specified in Start Year is greater than that in the named year column.
X <- X %>%
mutate(`2017` = ifelse(as.numeric(`Start Year`) > 2017, 0, `2017`)) %>%
mutate(`2018` = ifelse(as.numeric(`Start Year`) > 2018, 0, `2018`))
I need to repeat this for multiple years but am unsure how to reference the columns named 2017
, 2018
etc. in a loop. Thanks in advance.