Re: [R example for org-table with ifs]

2021-07-08 Thread Greg Minshall
Uwe,

> Thanks but I have to disappoint you the correct result should be 10.1

ah, well.  :)

i realized you probably wanted the table back.  below it is, with your
explanation of "@3$3".

> Thanks I will play around a bit, but for the moment I think I have to
> stick with calc

well, takes all kinds.  :)

cheers, Gerg



#+begin_src R :var some=thing :session R :colnames yes
  ## in imported colnames, spaces are replaced with periods
  some[, "Result"] <-
ifelse(some[, "DMNI.H"] > 10, (some[, "DMNI.H"] - 10.0) *
 (some[X == "Weight:", "Weight2"]),
   0.0) +
(min(10, some[, "DMNI.H"]) * some[X == "Weight:", "ExNDM.I"]) +
(ifelse(some[, "ExNDNM.J"] > 10, some[, "ExNDNM.J"] - 10 *
 some[X == "Weight:", "DMNI.H"], 0)) +
(min(10, some[, "ExNDNM.J"]) *
 some[X == "Weight:", "ExNDNM.J"]) +
(some[X == "Weight:", "Result"] *
 some[, "Result"])

  some
#+end_src

#+RESULTS:
| X   | DMI.G | DMNI.H | ExNDM.I | ExNDNM.J | Result | Weight2 |
|-+---++-+--++-|
| Weight: | 1 |0.2 |   1 |  0.1 || 0.1 |
| User1   | 0 |  0 |  11 |0 |   10.1 | |



Re: [R example for org-table with ifs]

2021-07-08 Thread Uwe Brauer
>>> "GM" == Greg Minshall  writes:

Greg


> Uwe,
> well, *i* no longer remember how to read calc-like expressions.  and,
> i'm a notoriously poor R coders.  assuredly the following is not doing
> what you want, but possibly you'll get the idea.  (if 102.01 is, indeed,
> the correct answer, feel free to buy me a hot fudge sundae some day. :)


Thanks but I have to disappoint you the correct result should be 10.1

> cheers, Greg

> #+name: thing
> | / | <>  |<> | <> |  <> |   <> | <> | <>  |

> |   | | DMI G | DMNI H | ExNDM I | ExNDNM J | Result | Weight2 |
> |   | Weight: | 1 |0.2 |   1 |  0.1 || 0.1 |
> |---+-+---++-+--++-|
> |   | User1   | 0 |  0 |  11 |0 | 10.1   | |
> |---+-+---++-+--++-|

> #+TBLFM: $7=if($3>10,($3-10)*@3$8,0)+ min(10,$3)*@3$3+ min(10,$4)*@3$4 + 
> if($5>10,($5-10)*@3$8,0)+min(10,$5)*@3$5 +@3$6*$6;f1::

> - does "@3$3" mean the third column in the third row? 
yes
>   - is that the "DMNI H" column? That is 0.2
>   - is that the "User1" row? 

No, it is the weight row

> i replace "@3" with the last row of the input table.

> #+begin_src R :var some=thing :session R :colnames yes
>   ## in imported colnames, spaces are replaced with periods
>   some[,"Result"] <- ifelse(some[,"DMNI.H"] > 10, (some[, "DMNI.H"] - 10.0) *
>  (some[nrow(some), 
> "Weight2"]),
> 0.0) +
> (min(10, some[, "DMNI.H"]) * some[nrow(some), "ExNDM.I"]) +
> (ifelse(some[, "ExNDNM.J"] > 10, some[, "ExNDNM.J"] - 10 * 
> some[nrow(some), "DMNI.H"], 0)) +
> (min(10, some[, "ExNDNM.J"]) * some[nrow(some), "ExNDNM.J"]) +
> (some[nrow(some), "Result"] * some[, "Result"])
> #+end_src

Thanks I will play around a bit, but for the moment I think I have to
stick with calc

Uwe 


smime.p7s
Description: S/MIME cryptographic signature


Re: [R example for org-table with ifs] (was: [External] : Re: export org table to other formats (gnumeric or scalc or xlsx))

2021-07-07 Thread Greg Minshall
Uwe,

well, *i* no longer remember how to read calc-like expressions.  and,
i'm a notoriously poor R coders.  assuredly the following is not doing
what you want, but possibly you'll get the idea.  (if 102.01 is, indeed,
the correct answer, feel free to buy me a hot fudge sundae some day. :)

cheers, Greg

#+name: thing
| / | <>  |<> | <> |  <> |   <> | <> | <>  |
|   | | DMI G | DMNI H | ExNDM I | ExNDNM J | Result | Weight2 |
|   | Weight: | 1 |0.2 |   1 |  0.1 || 0.1 |
|---+-+---++-+--++-|
|   | User1   | 0 |  0 |  11 |0 | 10.1   | |
|---+-+---++-+--++-|
#+TBLFM: $7=if($3>10,($3-10)*@3$8,0)+ min(10,$3)*@3$3+ min(10,$4)*@3$4 + 
if($5>10,($5-10)*@3$8,0)+min(10,$5)*@3$5 +@3$6*$6;f1::

- does "@3$3" mean the third column in the third row?
  - is that the "DMNI H" column?
  - is that the "User1" row?

i replace "@3" with the last row of the input table.

#+begin_src R :var some=thing :session R :colnames yes
  ## in imported colnames, spaces are replaced with periods
  some[,"Result"] <- ifelse(some[,"DMNI.H"] > 10, (some[, "DMNI.H"] - 10.0) *
 (some[nrow(some), "Weight2"]),
0.0) +
(min(10, some[, "DMNI.H"]) * some[nrow(some), "ExNDM.I"]) +
(ifelse(some[, "ExNDNM.J"] > 10, some[, "ExNDNM.J"] - 10 * some[nrow(some), 
"DMNI.H"], 0)) +
(min(10, some[, "ExNDNM.J"]) * some[nrow(some), "ExNDNM.J"]) +
(some[nrow(some), "Result"] * some[, "Result"])
#+end_src

#+RESULTS:
|  x |
||
||
| 102.01 |



Re: [R example for org-table with ifs]

2021-07-07 Thread Eric S Fraga
On Wednesday,  7 Jul 2021 at 09:01, Uwe Brauer wrote:
> Out of curiosity do you have an example of using R to generate stuff
> like this.

I don't; sorry.  I don't use R myself directly although my PhD students
do.  Others on this list have quite a bit of experience with R so maybe
somebody else can chime in.

-- 
: Eric S Fraga via Emacs 28.0.50, Org release_9.4.6-577-gf76d4d
: Latest paper written in org: https://arxiv.org/abs/2106.05096



[R example for org-table with ifs] (was: [External] : Re: export org table to other formats (gnumeric or scalc or xlsx))

2021-07-07 Thread Uwe Brauer
>>> "ESF" == Eric S Fraga  writes:

> On Monday,  5 Jul 2021 at 16:48, Uwe Brauer wrote:
>> Well I do that myself basically, but my main problem is now: *formulas*, I
>> have to collaborate with colleagues using excel and I have to work with
>> their formulas in a way or another. 

> Tell them to use R... ;-)

Out of curiosity do you have an example of using R to generate stuff
like this.


#+begin_src elisp
| / | <>  |<> | <> |  <> |   <> | <> | <>  |
|   | | DMI G | DMNI H | ExNDM I | ExNDNM J | Result | Weight2 |
|   | Weight: | 1 |0.2 |   1 |  0.1 || 0.1 |
|---+-+---++-+--++-|
|   | User1   | 0 |  0 |  11 |0 | 10.1   | |
|---+-+---++-+--++-|
#+TBLFM: $7=if($3>10,($3-10)*@3$8,0)+ min(10,$3)*@3$3+ min(10,$4)*@3$4 + 
if($5>10,($5-10)*@3$8,0)+min(10,$5)*@3$5 +@3$6*$6;f1::
#+end_src


smime.p7s
Description: S/MIME cryptographic signature