# R Dates - Recovering and Converting From Integers

One problem with R is that dates (class Date) are internally stored as integer numbers of days elapsed since 1 January 1970 and R sometimes loses the dateness of the variables and thinks of it only as an integer. So in the first line, we take the range of dates present in our data, allowing for the fact that some may be skipped. These are just integers — try looking at the output from min(m2\$day):max(m2\$day). To turn these back into dates we add them to the first date object: `

> min(m2\$day):max(m2\$day)
[1] 14245 14246 14247 14248 14249 14250 14251 14252 14253 14254 14255 14256 14257 14258 14259 14260 14261 14262 14263 14264 14265 14266 14267 14268 14269 14270 14271
[28] 14272 14273 14274 14275 14276 14277 14278 14279 14280 14281 14282 14283 14284 14285 14286 14287 14288 14289 14290 14291 14292 14293 14294 14295 14296 14297 14298
[55] 14299 14300 14301 14302 14303
>
> as.integer(as.Date('1970-01-01'))
[1] 0
>
> # the fix:
> as.Date('1970-01-01') + min(m2\$day):max(m2\$day)
[1] "2009-01-01" "2009-01-02" "2009-01-03" "2009-01-04" "2009-01-05" "2009-01-06" "2009-01-07" "2009-01-08" "2009-01-09" "2009-01-10" "2009-01-11" "2009-01-12"
[13] "2009-01-13" "2009-01-14" "2009-01-15" "2009-01-16" "2009-01-17" "2009-01-18" "2009-01-19" "2009-01-20" "2009-01-21" "2009-01-22" "2009-01-23" "2009-01-24"
[25] "2009-01-25" "2009-01-26" "2009-01-27" "2009-01-28" "2009-01-29" "2009-01-30" "2009-01-31" "2009-02-01" "2009-02-02" "2009-02-03" "2009-02-04" "2009-02-05"
[37] "2009-02-06" "2009-02-07" "2009-02-08" "2009-02-09" "2009-02-10" "2009-02-11" "2009-02-12" "2009-02-13" "2009-02-14" "2009-02-15" "2009-02-16" "2009-02-17"
[49] "2009-02-18" "2009-02-19" "2009-02-20" "2009-02-21" "2009-02-22" "2009-02-23" "2009-02-24" "2009-02-25" "2009-02-26" "2009-02-27" "2009-02-28"
>

`