[R] translate formula into R code

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Tue Jun 20 15:46:17 CEST 2017


This is an excellent exercise for you, the beginner. If you explicitly want a line-by-line translation and don't want to use the strengths of R (vectorization/functions) then there isn't much point in asking us to read the Introduction to R document that comes with the software for you. 

Please read the Posting Guide before posting again... your failure to switch your email client to plain text is going to lead to corruption of your question by the time w we see it eventually. 

PS you did not define what "res" is...
-- 
Sent from my phone. Please excuse my brevity.

On June 20, 2017 12:44:13 AM PDT, Wolfgang K <mails00000 at gmail.com> wrote:
>Hello,
>
>I am trying to implement the following formula using for loops and
>vectors.
>I am sure you can use some fancy R code to solve this but I would like
>to
>keep it simple and stick to for and vector/array if that is possible.
>
>TP = 200;
>RL = 50;
>TPR1 = TP - RL;
>TPR2 = TP + RL;
>PPO = 0;
>
>LSS = 0.1;
>
>counter = 1;
>
>for(i in res) {
>
>  # Even
>  if(counter %% 2 == 1) {
>    ls = abs((sum(LSS)* TP)) / (TPR1 - PPO);
>    LSS = c(LSS,ls);
>
>  }
>
>  # Odd
>  if(counter %% 2 == 0) {
>
>    ls = abs((sum(LSS)* TPR2)) / (TP - PPO);
>    LSS = c(LSS,ls);
>
>  }
>}



More information about the R-help mailing list