| To: | "John Pitchard" <johnpitchard@googlemail.com>, <s-news@lists.biostat.wustl.edu> |
|---|---|
| Subject: | Re: running cumulative product |
| From: | "Jordan, Paul" <paul.jordan@roche.com> |
| Date: | Tue, 19 Feb 2008 16:35:00 +0100 |
| In-reply-to: | <ee4b1650802190347k5e229665udb2aea3733bc2bfd@mail.gmail.com> |
| References: | <ee4b1650802190347k5e229665udb2aea3733bc2bfd@mail.gmail.com> |
| Thread-index: | AchzDPyrImbUBIJ6SSiCejn4aWaZSA== |
| Thread-topic: | running cumulative product |
|
Hi John,
try:
x[-length(x)]*x[-1]
Have
Fun!
Paul
From: John Pitchard [mailto:johnpitchard@googlemail.com] Sent: Tuesday, February 19, 2008 12:48 PM To: s-news@lists.biostat.wustl.edu Subject: running cumulative product Dear All,
I want to produce a running cumulative product. For example, if I have
x <- seq(0.1, 2, 0.1)
> x [1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 Then I want a sequence taking each pair of numbers, i.e. 0.1 and 0.2
(calculate the product), 0.2 and 0.3 (calculate the product), 0.3 and 0.4
(calculate the product),..., 1.9 and 2.0 (calculate the product). So I get a
vector of length 18 in this example (20 -2). The vector will look something like
this:
0.02 0.06.... 3.8
Does anyone know an efficient way to generate this sequence?
Many thanks in advance.
Regards,
John
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: running cumulative product, Romain Francois |
|---|---|
| Next by Date: | Re: NHPP, Tim Hesterberg |
| Previous by Thread: | Re: running cumulative product, Romain Francois |
| Indexes: | [Date] [Thread] [Top] [All Lists] |