[R] Month Difference
Berend Hasselman
bhh at xs4all.nl
Fri Sep 7 12:24:09 CEST 2012
On 07-09-2012, at 10:26, Rantony wrote:
> Hi,
>
> i need a small help.
>
> a<- as.Date("2012-01-01")
> b<- as.Date("2012-12-01")
> ------------------------------------
> My requirement what is, i need to get the month difference of these two
> dates.
One way is:
library(zoo)
(as.yearmon(b)-as.yearmon(a))*12
or
a.lt <- as.POSIXlt(a)
b.lt <- as.POSIXlt(b)
b.lt$mon-a.lt$mon
Searching in Google with "R date difference months" gives quite a few interesting results.
Berend
More information about the R-help
mailing list