[R] Cut Dates into bins
Jim Lemon
drjimlemon at gmail.com
Fri Jun 3 10:59:11 CEST 2016
Hi Tjun Kiat,
This seems to work:
daily_date<-as.Date(paste("2000-01",1:28,sep="-"),"%Y-%m-%d")
weekly_date<-as.Date(paste(c(1,8,15,22,28),"01/2000",sep="/"),
"%d/%m/%Y")
cut(daily_date,breaks=weekly_date,include.lowest=TRUE,
labels=paste("Week",1:4))
Jim
On Fri, Jun 3, 2016 at 6:00 PM, TJUN KIAT TEO <teotjunk at hotmail.com> wrote:
> I have two set of dates
>
> 2000-01-01
>
> 01/01/2000
>
> The second one occurs weekly and the first one occurs in daily. I would like to bin the first set of dates into the second set of dates. What is the best way to do it?
>
> I tried converting both formats into numeric formats
>
> DateBase=sort(as.numeric(as.POSIXlt(unique(Shipment$DateRequire),format="%Y-%m-%D",origin="1900-01-01")))
>
> Compare=as.numeric(as.POSIXlt(SMA$TIME_DATE,format="%d/%m/%y",origin="01/01/1900"))
>
> But the numeric numbers turned out to be very different.
>
> Tjun Kiat
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list