s-news
[Top] [All Lists]

running cumulative product

To: s-news@lists.biostat.wustl.edu
Subject: running cumulative product
From: "John Pitchard" <johnpitchard@googlemail.com>
Date: Tue, 19 Feb 2008 11:47:32 +0000
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; bh=Oaj4EU2e5DjfXiJGdFcQZxYxsLijXhkZhv0JzutuHqs=; b=vd3cDCcdnXwjcfMbsZMUuhpCIf25gNMgGDjJCkv8c53L6CrGMSBoDAGx2G61Vbu1REodPvY4gI8b7BUL7Yl+2qa7CibWVMsLJI3g8SL9q3JPgUiUPLJ3U+6dNYbi0bEEXkc4rJJqRKlRTXy0DaQu7xoBtDtNbqJEpRmI2bd4XbU=
Domainkey-signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=C0nC89JZxr91TU/nL5/iclOL66XuJZaUJyNNM3NpxA2uT/SuA3KP6Q/P5zS32eE8fW/wnnyk7chEeWp5ZCvNvF5ya3CcCXHQBuIO4+JsiZSOO3K48UoqJS8kQk5uPRCwImYuW2Ipodi7jPct0ABxxgllZ5vJcqwWVkvkIieS5Ks=
 
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>