simple ts() object question

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

simple ts() object question

StatWM
Dear Community,

say, I have an annual ts() object sampled from 1960 to 1969 like:

ta<-ts(1:10, start=1960, frequency=1)

How can I extract the value from the year 1965?

I mean, not by:

ta[6]

but by something like:
 
ta[1965]

where I'm directly referring to the year of the observation?

Thank you in advance!
Reply | Threaded
Open this post in threaded view
|

Re: simple ts() object question

Gabor Grothendieck
On Sun, Sep 5, 2010 at 12:08 AM, StatWM <[hidden email]> wrote:

>
> Dear Community,
>
> say, I have an annual ts() object sampled from 1960 to 1969 like:
>
> ta<-ts(1:10, start=1960, frequency=1)
>
> How can I extract the value from the year 1965?
>
> I mean, not by:
>
> ta[6]
>
> but by something like:
>
> ta[1965]
>
> where I'm directly referring to the year of the observation?
>
> Thank you in advance!
>

Use window.ts

> ta <- ts(1:10, start = 1960)
> window(ta, start = 1965, end = 1965)
Time Series:
Start = 1965
End = 1965
Frequency = 1
[1] 6


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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: simple ts() object question

Joshua Wiley-2
In reply to this post by StatWM
Hi,

There is probably an easier way, but this will work:

 ta[time(ta)==1965]

With your data, I get:

> ta[time(ta)==1965]
[1] 6

HTH,

Josh

On Sat, Sep 4, 2010 at 9:08 PM, StatWM <[hidden email]> wrote:

>
> Dear Community,
>
> say, I have an annual ts() object sampled from 1960 to 1969 like:
>
> ta<-ts(1:10, start=1960, frequency=1)
>
> How can I extract the value from the year 1965?
>
> I mean, not by:
>
> ta[6]
>
> but by something like:
>
> ta[1965]
>
> where I'm directly referring to the year of the observation?
>
> Thank you in advance!
>
> --
> View this message in context: http://r.789695.n4.nabble.com/simple-ts-object-question-tp2527085p2527085.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.
>



--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: simple ts() object question

StatWM
Thanks for the fast answers!