emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Uwe Brauer <oub@mat.ucm.es>
To: Greg Minshall <minshall@umich.edu>
Cc: Uwe Brauer <oub@mat.ucm.es>, emacs-orgmode@gnu.org
Subject: Re: [R example for org-table with ifs]
Date: Thu, 08 Jul 2021 08:26:24 +0200	[thread overview]
Message-ID: <87a6mxwcbz.fsf@mat.ucm.es> (raw)
In-Reply-To: 532197.1625721207@apollo2.minshall.org

[-- Attachment #1: Type: text/plain, Size: 2037 bytes --]

>>> "GM" == Greg Minshall <minshall@umich.edu> 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 

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]

  reply	other threads:[~2021-07-08  6:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-04 12:40 export org table to other formats (gnumeric or scalc or xlsx) Uwe Brauer
2021-07-04 22:00 ` Tim Cross
2021-07-04 23:22   ` [External] : " Daniel Ortmann
2021-07-05 14:48     ` Uwe Brauer
2021-07-05 14:56       ` Eric S Fraga
2021-07-06  4:01         ` Greg Minshall
2021-07-07  7:01         ` [R example for org-table with ifs] (was: [External] : Re: export org table to other formats (gnumeric or scalc or xlsx)) Uwe Brauer
2021-07-07 11:59           ` [R example for org-table with ifs] Eric S Fraga
2021-07-08  5:13           ` [R example for org-table with ifs] (was: [External] : Re: export org table to other formats (gnumeric or scalc or xlsx)) Greg Minshall
2021-07-08  6:26             ` Uwe Brauer [this message]
2021-07-08  7:33               ` [R example for org-table with ifs] Greg Minshall
2021-07-05  6:28   ` export org table to other formats (gnumeric or scalc or xlsx) Uwe Brauer
2021-07-05 14:51   ` Uwe Brauer
2021-07-05 22:29     ` Tim Cross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a6mxwcbz.fsf@mat.ucm.es \
    --to=oub@mat.ucm.es \
    --cc=emacs-orgmode@gnu.org \
    --cc=minshall@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).