[R] translate formula into R code

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Tue Jun 20 16:38:23 CEST 2017

Cc'd back to the list... always use reply-all.

You say res should have been LSS but LSS is a scalar so the for loop will only run once. What does a successful output look like for a sample input? How do you (we) know when success has been achieved?

In fact, what is the formula you want to implement?  If your code below is the definition of your "formula" then we are left with no destination. You either need to add a reference (paper citation?) or a set of inputs and corresponding outputs. 

Here are some resources that describe how to make a reproducible example [1][2][3]:

[1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

[2] http://adv-r.had.co.nz/Reproducibility.html

[3] https://cran.r-project.org/web/packages/reprex/index.html
Sent from my phone. Please excuse my brevity.

On June 20, 2017 7:01:23 AM PDT, Wolfgang K <mails00000 at gmail.com> wrote:
>well, I know how to use for-loop and create vectors. That is not the
>point. However, implementing this code is - at least for me - not as
>trivial as it seems since you have changes in the signs as well as
>changes in multiplication by TPR1 and TPR2. I spent hours trying to
>get this peace of code sorted out but I just don't get it working. I
>managed to calculate the first two values L2 and L3 but no more. Since
>I am not advanced in R, I was asking for help with basic functions
>which I do know already.
>Yes I changed so much that I forgot to change res back to LSS.
>2017-06-20 15:46 GMT+02:00 Jeff Newmiller <jdnewmil at dcn.davis.ca.us>:
>> 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>
>>>I am trying to implement the following formula using for loops and
>>>I am sure you can use some fancy R code to solve this but I would
>>>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