Fab*_*oli 7 format r date lubridate
我想在第 1 个月的两个指定时刻之间创建一个日期向量,如本主题中所述(创建两个日期之间的所有天数的向量),然后将其转换为用于数据可视化的因子。
但是,我想在 YYYY-Mon 中有日期,即。2010 年 2 月,格式。但到目前为止,我只设法使用标准格式 2010-02-01 的日期,使用这样的代码:
require(lubridate)
first <- ymd_hms("2010-02-07 15:00:00 UTC")
start <- ymd(floor_date(first, unit="month"))
last <- ymd_hms("2017-10-29 20:00:00 UTC")
end <- ymd(ceiling_date(last, unit="month"))
> start
[1] "2010-02-01"
> end
[1] "2017-11-01"
Run Code Online (Sandbox Code Playgroud)
如何将格式更改为 YYYY-Mon?
Aug*_*del 12
您可以使用format():
start %>% format('%Y-%b')
Run Code Online (Sandbox Code Playgroud)
要创建向量,请使用seq():
seq(start, end, by = 'month') %>% format('%Y-%b')
Run Code Online (Sandbox Code Playgroud)
Obs:使用大写“B”表示完整的月份名称:'%Y-%B'。