R class 润滑后变化

R class changes after lubridate

我正在尝试使用 lubridate 来提取日期中的月份,但是 class 发生了变化。这是我的代码示例

library(lubridate)
mydates<-c("10-10-2020","11-10-2020")
mydates <- as.Date(mydates,"%m-%d-%Y")
class(mydates)
mydates <- month(mydates, label=TRUE)
class(mydates)

我想继续把它作为 class 约会,但我也做不到。这是将图表绘制为日期。有什么建议吗?谢谢,

您似乎想使用 floor_date 转换为月份的第一天。

floor_date(mydates, unit = "months")

这样 2020 年 12 月将在 2021 年 1 月之前发生,因为您还有一个实际日期。

如果您只想在坐标轴中显示月份名称,那么这是关于绘图标签的问题,而不是lubridate