0

I'm using R and I have the following variables:

data$date1 (which is a date)
[1] "2012-01-01" "2012-01-01" "2012-01-01"

and

data$date2  (which is a numeric)
[1] 201602

I need to do a date difference but I don't know how to do it. I need to calculate the months difference.

Any help will be really appreciated.

nrussell
  • 18,382
  • 4
  • 47
  • 60
  • 2
    Try `as.Date`, answers here http://stackoverflow.com/q/6242955 and the `months` function – Frank May 09 '16 at 13:07
  • 1
    The answer to the title of your question is `as.Date(paste0(data$date2,"01"), format="%Y%m%d")`. This question has the rest [Number of months between two dates](http://stackoverflow.com/questions/1995933/number-of-months-between-two-dates) – Pierre L May 09 '16 at 13:34
  • The problem is that I don't know how to transform the data$date2 into a date value – thundermils May 09 '16 at 14:01

0 Answers0