r - Grouping posixct-data non-linear -
i have got series of video uploads , want show how many videos has been uploaded in last month, half year, year, 2, year, 3, year ...
published_at
of type posixct
, should transformed factor
levels above.
is there nice way so? seems not first person thinking this.
the dates like:
date<- as.posixct(c("2015-12-11 00:00:01", "2016-01-11 00:00:01", "2014-01-11 00:00:01", "2015-12-11 00:00:01", "2016-04-04 08:22:01", "2013-12-11 00:00:01") , format= "%y-%m-%d %h:%m:%s") df<- data.frame(date, number=ceiling(abs(rnorm(1:6))))
i thought using cut
-function don't know how specify breaks
my approach this:
published_at <- as.posixct(c("2015-12-11 00:00:01") , format= "%y-%m-%d %h:%m:%s") library(lubridate) half_year <- interval(start = ymd(sys.date() - months(6)), end = ymd(sys.date()), tzone = "ecst") year <- interval(start = ymd(sys.date() - months(12)), end = ymd(sys.date()), tzone = "ecst") two_years <- interval(start = ymd(sys.date() - months(24)), end = ymd(sys.date()), tzone = "ecst") published_at %within% c(half_year, year, two_years) #[1] false true true
you can dates , perhaps via lapply()
or else.
Comments
Post a Comment