An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120625/d7415817/attachment.pl>
Help in subsetting a vector incrementally
2 messages · Raghuraman Ramachandran, James
2 days later
On Mon, Jun 25, 2012 at 7:07 AM, Raghuraman Ramachandran
<rramachandran at jefferies.com> wrote:
I have an array a, and I am running a formula which is simply 1+Delt(a) Is it possible to get an output vector which will have sequential values of 1+Delt(a) please? I tried 1+Delt(a[1: (length(a)-1)]) and it works. But then every time I need the previous value I need to write this which is not ideal.
Raman, I think it would help if you could provide a bit more information. For example, some sample data showing the input and expected output. Additionally, some clarification of whether you are using the Delt function from quantmod. For example:
library(quantmod) a <- 1:10 1 + Delt(a)
Delt.1.arithmetic [1,] NA [2,] 2.000000 [3,] 1.500000 [4,] 1.333333 [5,] 1.250000 [6,] 1.200000 [7,] 1.166667 [8,] 1.142857 [9,] 1.125000 [10,] 1.111111
1 + Delt(a[1:(length(a) - 1)])
Delt.1.arithmetic [1,] NA [2,] 2.000000 [3,] 1.500000 [4,] 1.333333 [5,] 1.250000 [6,] 1.200000 [7,] 1.166667 [8,] 1.142857 [9,] 1.125000 What should the desired output be? James