[R] constructing a sequence of POSIXct dates

Michael Weylandt michael.weylandt at gmail.com
Mon Apr 21 17:04:14 CEST 2014



On Apr 21, 2014, at 10:55, Erin Hodgess <erinm.hodgess at gmail.com> wrote:

> Never mind....solved it

xkcd.com/979/


> 
> 
> On Mon, Apr 21, 2014 at 9:48 AM, Erin Hodgess <erinm.hodgess at gmail.com>wrote:
> 
>> Hello!
>> 
>> I have the following:
>> 
>>> time1a <- as.POSIXct(paste(2008,08,01,sep="-"))
>>> time1b <- as.POSIXct(paste(2008,08,11,sep="-"))
>>> time1a
>> [1] "2008-08-01 CDT"
>>> time1b
>> [1] "2008-08-11 CDT"
>>> time1c <- seq(from=as.POSIXct(time1a),to=as.POSIXct(time1b),by="days")
>>> class(time1c)
>> [1] "POSIXct" "POSIXt"
>>> print(time1c)
>> [1] "2008-08-01 CDT" "2008-08-02 CDT" "2008-08-03 CDT" "2008-08-04 CDT"
>> [5] "2008-08-05 CDT" "2008-08-06 CDT" "2008-08-07 CDT" "2008-08-08 CDT"
>> [9] "2008-08-09 CDT" "2008-08-10 CDT" "2008-08-11 CDT"
>> 
>> I have generated the correct sequence.  However, time1c must be a POSIXct
>> object.  How do I remove the second class, please?

Don't. POSIXt is a virtual superclass to which all POSIXct objects should belong. 

Code which works with POSIXct objects but not POSIXct/POSIXt is almost certainly buggy. 

Michael




More information about the R-help mailing list