A Date
involves 'year', 'month' and 'day'. If one of them is not specified i.e. the 'year', it gets the current 'year'. Avoid that by paste
ing the 'year' and specify the four-digit year format
(%Y
)
as.Date(paste0("20-May", "-2019"), format = "%d-%b-%Y")
#[1] "2019-05-20"
Or another option is to change the year
by assigning
library(lubridate)
date1 <- as.Date("20-May", format = "%d-%b")
year(date1) <- 2019
date1
#[1] "2019-05-20"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…