【发布时间】:2022-12-05 15:16:33
【问题描述】:
当我在 r 中使用“as.Date”命令时,它返回 Na 作为结果,我尝试了不同的方法,比如将它转换为 POSIXt 格式,但它不起作用
#this is the format i need it to read
format(Sys.Date(), "%B de %Y")
# this is an example of what i need
date="noviembre de 2022"
class(date)
#this is what i tried
date2 <- strptime(date, format = "%B de %Y")
class(date2)
date3 <- as.Date(date2,format="%B de %Y")
class(date3)
date3
这就是我得到的 na as result
我想要类似的东西
navidad2021=as.Date("25 Diciembre 2021",format="%d %B %Y")
navidad2021
[1] "2021-12-25"
但在这种格式
format(Sys.Date(), "%B de %Y")
[1] "December de 2022"
非常感谢你的帮助
【问题讨论】: