Skip to content

dates in R

5 messages · sirmeelo at gmail.com, Brandon Hurr, David Winsemius +1 more

#
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
#
On Oct 23, 2010, at 2:09 PM, Turner Rolf wrote:

            
All true. I have had to do steps equivalent to this, but learned from  
my experience. I now use colClasses to import dates as "character"  
rather than numeric.
1 day later
#