Hello,

Try

library(zoo) # needed for as.yearmon

x <- c(201009, 201010, 201011, 201101, 201102)
(y <- as.Date(paste(x, "01", sep=""), format="%Y%m%d"))
y - y[1]
12*(as.yearmon(y) - as.yearmon(y[1]))

Note that to have a time difference between dates we need days (paste).

Hope this helps,

Rui Barradas

Em 01-06-2012 12:31, Tammy Ma escreveu:
HI, R-Users:

I got a questions. have been struggling so long time....

I have this data:

m1$Year_Month
   201009 201010 201011 201101 201102
min(m1$Year_Month)
   201009

I want to calculate the following two answers, how do I program it?

difference in Month?????
  [1] 0 1 2 4 5

difference in Days?????
  0  31  61 ....

Thank you in advance!!!

Tammy
                                        
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
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.

______________________________________________
R-help@r-project.org mailing list
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.

Reply via email to