给定一个POSIXct日期时间,如何提取月份的第一天进行聚合?
library(lubridate)
full.date <- ymd_hms("2013-01-01 00:00:21")发布于 2015-11-12 01:01:58
流苏酸盐有一个名为floor_date的函数,它可以循环日期和时间。使用unit = "month"调用它可以实现您想要的结果:
library(lubridate)
full.date <- ymd_hms("2013-01-01 00:00:21")
floor_date(full.date, "month")
[1] "2013-01-01 UTC"发布于 2014-05-12 07:15:16
我看不出有什么理由使用润滑油:
full.date <- as.POSIXct("2013-01-11 00:00:21", tz="GMT")
monthStart <- function(x) {
x <- as.POSIXlt(x)
x$mday <- 1
as.Date(x)
}
monthStart(full.date)
#[1] "2013-01-01"发布于 2014-05-12 06:51:56
first.of.month <- ymd(format(full.date, "%Y-%m-01"))
first.of.month
[1] "2013-01-01 UTC"https://stackoverflow.com/questions/23602706
复制相似问题