Re: [R] Creating zoo object on monthly time series

From: Megh Dal <megh700004_at_yahoo.com>
Date: Sun, 01 Jun 2008 06:37:58 -0700 (PDT)


I got following:

> z <- zoo(data1[,3], as.yearmon(data1[,1], "%b-%y"))
> head(z)

Jan 0001 Jan 0002 Jan 0003 Jan 0004 Jan 0005 Jan 0006  1206.68 782.45 1187.00 1398.77 1883.23 1431.80

> z <- zoo(data1[,3], as.Date(as.yearmon(data1[,1], "%b-%y")))
> head(z)

0001-01-01 0002-01-01 0003-01-01 0004-01-01 0005-01-01 0006-01-01

   1206.68 782.45 1187.00 1398.77 1883.23 1431.80

Nowhere 1980 is coming. Any better suggestion?

Gabor Grothendieck <ggrothendieck_at_gmail.com> wrote: On Sun, Jun 1, 2008 at 8:47 AM, Gabor Grothendieck  wrote:
> On Sun, Jun 1, 2008 at 8:35 AM, Megh Dal wrote:
>> Hi all,
>>
>> I have following monthly time series :
>>
>>> head(data1)
>> V1 V2 V3
>> 1 Nov-80 NA 1007.44
>> 2 Dec-80 NA 982.05
>> 3 Jan-81 NA 994.25
>> 4 Feb-81 NA 996.31
>> 5 Mar-81 NA 939.91
>> 6 Apr-81 NA 923.32
>
> If the suggestion below does not work then try
> dput(head(data1)) to display it in an unambiguous form that is
> readily re-input into R.
>
>>
>> Now I want to convert it to a 'zoo' object. I wrote following syntax :
>>
>> ss = zoo(data1[,3], as.Date(data1[,1], format="%m/%y"))
>>
>
> See ?strptime and try "%b-%y"

That should be:

   z <- zoo(data1[,3], as.yearmon(data1[,1], "%b-%y"))

or, if you want it as Date instead of yearmon:

   z <- zoo(data1[,3], as.Date(as.yearmon(data1[,1], "%b-%y")))

>
>> However I got following :
>>> head(ss)
>>
>> 1007.44 982.05 994.25 996.31 939.91 923.32
>>
>>
>> Can anyone please tell me what will be the correct syntax?
>>
>> Thanks
>>
>>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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.
>>
>

       
	[[alternative HTML version deleted]]

______________________________________________
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 Mon 02 Jun 2008 - 04:10:54 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 Mon 02 Jun 2008 - 07:30:38 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