[R] how to extract data by specific months from a monthly ts object

From: tom soyer <tom.soyer_at_gmail.com>
Date: Sun, 20 Jan 2008 19:09:17 -0600


Hi,

I am trying to extract data from a ts object by month, e.g., extract Jan, Feb, and Aug data from a monthly ts object. I tried the following but it didn't work:

> xa=1:50
> ta=ts(xa,start=c(1990,1),frequency=12)
> ta[cycle(ta)==c(1,2)] # this method works but it's not what I want
 [1] 1 2 13 14 25 26 37 38 49 50
> ta[cycle(ta)==c(1,2,8)] # this method doesn't work, unfortunately
 [1] 1 2 13 14 25 26 37 38 49 50
Warning message:
In `==.default`(cycle(ta), c(1, 2, 8)) :   longer object length is not a multiple of shorter object length

somehow ta[cycle(ta)==c(1,2)] works. But what I really need is for ta[cycle(ta)==c(1,2,8)] to work, and it doesn't. Does anyone know how could to do this kinds of data extraction?

Thanks!

-- 
Tom

	[[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 21 Jan 2008 - 01:17:13 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 21 Jan 2008 - 02:30:07 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