I have a tibble
with several columns containing dates, some of which are in the future (e.g., 2019-08-26). I need to replace the dates that are in the future with NA
, and want to do so using dplyr
.
So far I have the following, which does not work:
library(lubridate)
library(dplyr)
library(tibble)
d <- tibble("ID" = 1:9,
"Date1" = as_date(c("2019-08-05", "2019-08-26", "2019-08-26",
"2019-08-26", "2019-07-29", "2019-08-12",
"2019-08-19", "2019-08-26", "2019-08-26")),
"Date2" = as_date(c("2019-08-12", "2019-09-02", "2019-09-02",
"2019-09-02", "2019-08-05", "2019-08-19",
"2019-08-26", "2019-09-02", "2019-09-02")))
d %>%
select("Date1") %>%
replace(. > today(), NA) #This line doesn't work