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] 06/01/98 06/25/98 07/28/98 08/01/98 09/15/98 09/28/98

as.POSIXct(testDATES)
[1] NA NA NA NA NA NA

format(as.POSIXct(testDATES), "%m/%d/%Y")
[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)
x
"1899 12 30 12 0 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")
"02/27/92" "02/27/92" "01/14/92" "02/28/92" "02/01/92"

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


-- ********************************************************************* Brian Beckage Department of Botany University of Vermont Marsh Life Science Building Burlington, VT 05405

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to