将年份和月份(“yyy-mm”格式)转换为日期?我有一个如下所示的数据集:Month count2009-01 122009-02 3102009-03 23792009-04 2342009-05 142009-08 12009-09 342009-10 2386我想要绘制数据(月份为x值,计数为y值)。由于数据中存在空白,所以我希望将月份的信息转换为日期。我试过:as.Date("2009-03", "%Y-%m")但没有用。怎么了?看起来,As.Date()也需要一天,并且无法为一天设置一个标准值?哪个功能解决了我的问题?
4 回答
一只斗牛犬
TA贡献1784条经验 获得超2个赞
parse_date_time
fast_strptime
lubridate
> parse_date_time(dates1, "ym")[1] "2009-01-01 UTC" "2009-02-01 UTC" "2009-03-01 UTC"> fast_strptime(dates1, "%Y-%m")[1] "2009-01-01 UTC" "2009-02-01 UTC" "2009-03-01 UTC"
parse_date_time
fast_strptime
strptime
.
tz
> parse_date_time(dates1, "ym", tz = "CET")[1] "2009-01-01 CET" "2009-02-01 CET" "2009-03-01 CET"
truncated
> parse_date_time(dates2, "ymdHMS", truncated = 3)[1] "2012-06-01 12:23:00 UTC" "2012-06-01 12:00:00 UTC" "2012-06-01 00:00:00 UTC"
dates1 <- c("2009-01","2009-02","2009-03")dates2 <- c("2012-06-01 12:23","2012-06-01 12",'2012-06-01")
- 4 回答
- 0 关注
- 2396 浏览
添加回答
举报
0/150
提交
取消