[R-SIG-Finance] Help in subsetting a vector incrementally

J Toll jctoll at gmail.com
Thu Jun 28 05:27:53 CEST 2012


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



More information about the R-SIG-Finance mailing list