[R] Dates in R

Rui Barradas ruipbarradas at sapo.pt
Mon May 7 15:11:44 CEST 2012


Hello,

Try

x <- 20102010

as.Date(as.character(x), format="%Y%d%m")
[1] "2010-10-20"
as.POSIXct(as.character(x), format="%Y%d%m")
[1] "2010-10-20 BST"

Note that you must pass x as a character vector.
If not, the date functions will see it as the number of days since an origin
such as 1970-01-01 or others. See the help page for as.POSIXct for examples
on this.

?as.POSIXct

This is obviously not your case, so the examples above should solve it.
For date formats see

?strptime

Hope this helps,

Rui Barradas


--
View this message in context: http://r.789695.n4.nabble.com/Dates-in-R-tp4614266p4614751.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list