I think a lag() command will work for you -- but a more helpful piece
of advise is probably to use xts or zoo packages rather than the base
ts. Most people find ts very hard to work with and find that all their
difficulties magically go away when they use those classes.

In xts: it would be something like:

mean(tail(rp,9))
mean(lag(tail(rp,9)))

Michael

On Wed, Oct 26, 2011 at 12:33 PM, Iara Faria <iarag...@yahoo.com.br> wrote:
> Hi all,
>
> I have 5 series  (5 ts objects: rp, igpm, ereal, jurosreal, crescpib), and 
> want to create a vector with the means of the last values of each variable.
> What I did was this:
>
> mrp1<-mean(tail(rp,9))
> migpm1<-mean(tail(igpm,9))
> mereal1<-mean(tail(ereal,9))
> mjr1<-mean(tail(jurosreal,9))
> mcp1<-mean(tail(crescpib,9))
> means=rbind(mrp1,migpm1,mereal1,mjr1,mcp1)
>
> They are monthly series, from 1995.1 to 2011.6.
> So what I did was generate the mean of each variable for [2010.10 to 2011.6] 
> (9 months, as I wanted).
> But now I want to create a vector with the means of the last 9 values 
> [2010.10 to 2011.6] AND the means of of 9 months but deslocated one month, 
> that is, [2010.9 to 2011.5].
>
> I tried to find examples of this but with no help.
> Can anyone give a hand?
>
> Thanks in advance.
> Regards,
> Iara
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help@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.
>
>

______________________________________________
R-help@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.

Reply via email to