[R] as.POSIXct problem
Brian Beckage
Brian.Beckage at uvm.edu
Sat Mar 6 04:32:56 CET 2004
>
>
>At any rate, one idea is to create the chron dates
>relative to the default origin like this:
>
> > testDATES<-c(35947,35971,36004,36008,36053,36066)
>> testDATES.chron <- chron("12/30/1899") + testDATES
> > as.POSIXct(testDATES.chron)
>[1] "1998-05-31 20:00:00 Eastern Daylight Time"
>[2] "1998-06-24 20:00:00 Eastern Daylight Time"
>[3] "1998-07-27 20:00:00 Eastern Daylight Time"
>[4] "1998-07-31 20:00:00 Eastern Daylight Time"
>[5] "1998-09-14 20:00:00 Eastern Daylight Time"
>[6] "1998-09-27 20:00:00 Eastern Daylight Time"
>
>Does that make any difference on your system?
This worked on my machine as well! I'm not sure why this made a
difference...but thanks.
Brian
>
>---
>Date: Fri, 5 Mar 2004 11:35:45 -0500
>From: Brian Beckage <Brian.Beckage at uvm.edu>
>To: <r-help at stat.math.ethz.ch>
>Subject: [R] 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] 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
>
>
>
>_______________________________________________
>No banners. No pop-ups. No kidding.
>Introducing My Way - http://www.myway.com
--
*********************************************************************
Brian Beckage
Department of Botany
University of Vermont
Marsh Life Science Building
Burlington, VT 05405
Phone: 802 656-0197
Fax : 802 656-0440
email: Brian.Beckage at uvm.edu
web : www.uvm.edu/~bbeckage
More information about the R-help
mailing list