[R] Subtracting time series

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Tue Feb 2 16:07:19 CET 2010


On Tue, 2 Feb 2010, Nick Torenvliet wrote:

> Hi all,
>
> I've got a time series object (xts) called table.  Table contains closing
> price and volume for each market day of 2009 on a given equity.
>
> I'd like to get another xts object, say table2, that contains for each
> market day holds the close of that day minus the close of the day before and
> the volume of that day minus the volume of the day before.
>
> So
>
> table2 <- table[x,] - table[(x-1),]

This does not do what you want because xts is smart and aligns along the 
time index.

> But I can't quit get the syntax, any help would be appreciated.

Look at diff() and lag() and their respective methods for "xts" series.
Z

> Nick
>
> 	[[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.
>
>



More information about the R-help mailing list