I am new to R and have only limited knowledge. I have a list of dates here that I would like to mutate . If the "Date" is less than the current date I would like the "Date" value to be replaced with "NA" in the same column. I tried using the mutate function, but I could not figure out the logic to make this code run.
Start <- structure(list(Date = structure(c(1620345600, 1621123200, 1624752000,
1625184000, NA, 1625356800, 1627084800, 1628035200, 1628985600,
1631404800, 1631577600, 1627344000, 1632182400, 1627430400, 1628985600,
1632441600, 1632441600, 1631145600, 1634083200, 1632441600, 1630195200
), class = c("POSIXct", "POSIXt"), tzone = "UTC")), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -21L))
current_date <- Sys.Date()
mutate(Date=ifelse(Date < current_date, Date, NA))
When running this code, I get the following error message.
Error in `<.default`(Date, current_date) :
comparison (3) is possible only for atomic and list types
Using the following data, I tried the following code but could not get it to work.
Thank you for your help!