Re: [R] adress the current index

About this list Date view Thread view Subject view Author view Attachment view

From: Thomas Petzoldt (thpe@hhbio.wasser.tu-dresden.de)
Date: Wed 26 May 2004 - 01:25:37 EST


Message-id: <40B36571.6030005@hhbio.wasser.tu-dresden.de>

Mag. Ferri Leberl wrote:

> How can I adress the current index of a vector?
>
> I want to work with time series and therefore give the n-th element of a
> vector some value dependent on the value of the n-1th element.

Sorry, your question is not really clear, but possibly the following may
help:

1) If you have a vector x, you can create a shifted vector by removing
the first element, e.g.:

xnew <- x[-1] + somevalue # or apply a function f(x[-1])

2) The last element can be removed with:

xnew <- x[-length(x)]

3) ... and sometimes vector concatenation ?c or the ?ifelse function can
be useful in such circumstances.

Thomas P.

PS: there is more about such things in the docs.

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:12 EST