[R] difference between 2 dates: IN MONTHS the way Mothers compute it
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Mar 10 19:38:12 CET 2006
zoo has the "yearmon" class which will convert a date to a year +
0/12 to 11/12 to represent the month, disregarding the day, so:
library(zoo)
12 * as.numeric((as.yearmon("2006-03-07") - as.yearmon("2006-02-06"))) # 1
On 3/10/06, Smith, Phil <pzs6 at cdc.gov> wrote:
> Hi R-people:
>
> I need a function to compute the number of months between 2 dates, in the same way a mother would do it.
>
> For example, if a kid is born on February 6, the number of months between that date and March 7 is exactly 1 month, although it is only 29 days.
>
> Thank you!
> Phil Smith
> CDC
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list