Re: [R] date conversion

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Wed, 16 Mar 2011 23:22:05 -0400

On Wed, Mar 16, 2011 at 10:22 PM, Erin Hodgess <erinm.hodgess_at_gmail.com> wrote:
> Dear R People:
>
> I have a monthly time series which runs from January 1998 to December 2010.
>
> When I use tsp I get the following:
>
>> tsp(ibm$ts)
> [1] 1998.000 2010.917   12.000
>
>
> Is there an easy way to convert this to a seq.Date object, please?
>
> I would like to have something to the effect of
> 1998/01/01 .... 2010/12/01
>

This would be clearer if you gave a complete example but creating a sample series, ser, we can create a zoo series using Date class times like this:

> library(zoo)
> ser <- ts(seq(12*13), start = 1998, frequency = 12)
> tsp(ser)

[1] 1998.000 2010.917 12.000
> z <- as.zoo(ser)
> time(z) <- as.Date(as.yearmon(time(ser)))
> head(z)

1998-01-01 1998-02-01 1998-03-01 1998-04-01 1998-05-01 1998-06-01

         1 2 3 4 5 6

You might actually prefer to leave it as "yearmon" class in which case its

> z <- as.zoo(ser)
> time(z) <- as.yearmon(time(z))
> head(z)
Jan 1998 Feb 1998 Mar 1998 Apr 1998 May 1998 Jun 1998

       1 2 3 4 5 6

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Thu 17 Mar 2011 - 03:32:49 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 17 Mar 2011 - 04:00:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive