Your question is unclear. If the calculation of B[3] now depends on the
newly calculated value of B[2], then the answer is no: you must loop. If
B[3] is based on the original B[2] value, then the answer is yes, and the
solution is just a matter of simple indexing, which I leave as an exercise.

-- Bert

On Fri, Aug 27, 2010 at 10:17 AM, Marcus Drescher <dresc...@tum.de> wrote:

> Hi all,
>
> I want to calculate in each row a ratio based on number in the current row
> and the previous row.
> Is there a way to do this without for-loops because that is extremely slow.
>
>        A       B
> [1]     2       2
> [2]     2       3
> [3]     4       5,5
> ...
>
> B2 = A2 + 0.5*B1
>
>
> Thanks in advance.
> Best
> Marcus
>
> ______________________________________________
> R-help@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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to