Skip to content
Prev 45419 / 398498 Next

as.POSIXct problem

Hi all,

I'm having difficulty converting a 'dates' object to a POSIXct object:

testDATES<-c(35947,35971,36004,36008,36053,36066)

testDATES<-chron(dates=testDATES, format = c(dates = "m/d/y"), 
origin=c(month = 12, day = 30, year = 1899))
[1] NA NA NA NA NA NA
[1] NA NA NA NA NA NA

I've looked at the as.POSIXct function, traced the problem to ISOdate 
and then to strptime, e.g.,

x<-paste(year=1899, month=12, day=30, hour=12, min=0, sec=0)
strptime(x, "%Y %m %d %H %M %S")
[1] NA NA NA NA

However, strptime works fine below.

dates <- c("02/27/92", "02/27/92", "01/14/92",
                 "02/28/92", "02/01/92")
strptime(dates, "%m/%d/%y")
I've been reading through a whole suite of emails on the R archives 
regarding as.POSIXct problems but I have not found anything that 
solves my particular problem.  I need the dates to be of class 
POSIXct for use in the its package.

I'm using R 1.8.1 on Mac OS 10.3.2.  Any help is greatly appreciated.

Thanks,
Brian