How can I generate a vector of differences between each elemtn of an vector? i.e. a[i]=x[i]/x[i-1] -- View this message in context: http://n4.nabble.com/Deltas-or-changes-tp1585960p1585960.html Sent from the R help mailing list archive at Nabble.com.
You can try this: Reduce("/", as.data.frame(embed(x, 2))) On Tue, Mar 9, 2010 at 10:37 AM, ManInMoon <xmoon2000 at googlemail.com> wrote:> > How can I generate a vector of differences between each elemtn of an vector? > > i.e. a[i]=x[i]/x[i-1] > -- > View this message in context: http://n4.nabble.com/Deltas-or-changes-tp1585960p1585960.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Henrique Dallazuanna <wwwhsd <at> gmail.com> writes:> Reduce("/", as.data.frame(embed(x, 2))) > > ManInMoon <xmoon2000 <at> googlemail.com> wrote: > > > > How can I generate a vector of differences between each > elemtn of an vector?(you mean ratios, right?)> > > > i.e. a[i]=x[i]/x[i-1]x[-1]/x[-length(x)] might be a little easier to understand. exp(diff(log(x))) should work too (although a big waste of computational power ...)
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
On Tue, 9 Mar 2010 05:37:52 -0800 (PST) ManInMoon <xmoon2000 @googlemail.com> wrote:> How can I generate a vector of differences between each elemtn of an vector?diff(x) -- Karl Ove Hufthammer
Hi, I am new to R. What does a negative amount in an index do? i.e. x[-lenght[x]] -- View this message in context: http://n4.nabble.com/Deltas-or-changes-tp1585960p1587408.html Sent from the R help mailing list archive at Nabble.com.
Please learn to Read The Fine Manual: ?"[" will give you the answer. -Ista On Wed, Mar 10, 2010 at 8:43 AM, ManInMoon <xmoon2000 at googlemail.com> wrote:> > Hi, I am new to R. > > What does a negative amount in an index do? > > i.e. x[-lenght[x]] > -- > View this message in context: http://n4.nabble.com/Deltas-or-changes-tp1585960p1587408.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org
It does help much. Just one line about x[-1] Is there more comprehensive help anywhere? -- View this message in context: http://n4.nabble.com/Deltas-or-changes-tp1585960p1587939.html Sent from the R help mailing list archive at Nabble.com.
On Mar 10, 2010, at 2:50 PM, ManInMoon wrote:> > It does help much. > > Just one line about x[-1] > > Is there more comprehensive help anywhere?http://cran.r-project.org/doc/manuals/R-lang.html#Indexing> -- > View this message in context: http://n4.nabble.com/Deltas-or-changes-tp1585960p1587939.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius, MD West Hartford, CT