[R-SIG-Mac] dates in R

Turner Rolf r.turner at auckland.ac.nz
Sat Oct 23 23:09:12 CEST 2010



 sirmeelo at gmail.com [sirmeelo at gmail.com] wrote:

Hi list,

I am having trouble getting R to read and display dates correctly. My dates
are in the form of day (no space) month (no space) year, for example: 250706
and sometimes 50906.

Any guidance would be appreciated...Thanks.

(1) This question has nothing to do with Mac computers.  It should have been sent to r-help.

(2) The problem seems to me to be the inconsistency in the number of digits representing
"day",  To remedy this, paste on a zero and then remove redundant zeroes:

foo <- function(x) {
              x <- paste(0,x,sep="")
              x <- substr(x,nchar(x)-5,nchar(x))
              strptime(x,format="%d%m%y")
}

x <- c(250706,50906)
foo(x)
[1] "2006-07-25" "2006-09-05"

HTH.

     cheers,

           Rolf Turner


More information about the R-SIG-Mac mailing list