[R] Deltas or changes

Dimitris Rizopoulos d.rizopoulos at erasmusmc.nl
Tue Mar 9 15:10:52 CET 2010


try this:

x <- runif(100)

a <- x[-1] / x[-length(x)]
a


I hope it helps.

Best,
Dimitris


On 3/9/2010 2:37 PM, ManInMoon wrote:
>
> How can I generate a vector of differences between each elemtn of an vector?
>
> i.e. a[i]=x[i]/x[i-1]

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014



More information about the R-help mailing list