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.

______________________________________________
[EMAIL PROTECTED] 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

Reply via email to