我有一个date列,其日期值如下所示:
date = c("1/6/2022", "1/6/2022", "1/19/2022", "1/20/2022")当我尝试使用lubridate::mdy将其转换为新日期列时,我得到:
library(lubridate)
date_new = lubridate::mdy(date)
print(date_new)
[1] "2022-01-06" "2022-01-06" "2022-01-19" "2022-01-20"
# Desired output (mm-dd-yyyy or mm/dd/yyyy):
[1] "01-06-2022" "01-06-2022" "01-19-2022" "01-20-2022"如何使用lubridate获得所需的输出
发布于 2022-09-29 16:12:15
我们可以使用format
format(lubridate::mdy(date), '%m-%d-%Y')
[1] "01-06-2022" "01-06-2022" "01-19-2022" "01-20-2022"https://stackoverflow.com/questions/73898634
复制相似问题