emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: table: problem with nan and if


From: Tim Cross
Subject: Re: table: problem with nan and if
Date: Tue, 22 Jun 2021 08:26:40 +1000
User-agent: mu4e 1.5.13; emacs 28.0.50

Uwe Brauer <oub@mat.ucm.es> writes:

> Hi
>
> I have the following table 
>
> #+begin_src elisp
> #+NAME: test
> | Name  | E1 | E2 |  E3 | Result1 | Result2 | Final |
> |-------+----+----+-----+---------+---------+-------|
> | User1 |    |    |     |         |       8 | nan    |
> | User2 |    |    |     |         |         |        |
> | User3 |  1 |  0 | 3.5 |     4.5 |     5.8 | 4.8    |
> |-------+----+----+-----+---------+---------+-------|
> #+TBLFM: $5=if(typeof(vsum($2..$4)) == 12, string(" "),vsum($2..$4));E 
> f-1::$7=if("$6" == "nan", string(" "),0.3*$5+0.6*$6); E f-1
> #+end_src
>
>
> The calculations for User2 and 3 are fine, but for User1, the final
> result is a  "nan".
>
> I see the problem is caused by ; E f-1 I don't understand why because
>
> As in 
>
> #+begin_src elisp
> | user1 | User2 |     |
> |-------+-------+-----|
> |       |     3 | nan |
> |     0 |     1 | 0.8 |
> #+TBLFM: $3=0.2*$1+0.8*$2; E f-1
> #+end_src
>
> I am not sure, but should I use something like 
>
> if("$5" == "nan", string(" "),0.6*$6); E;f-1
>
>
> But how can I combine both ifs, I am puzzled
>
> Any  help is strongly appreciated.
>
>

I'm not very familiar with calc, but am wondering if the issue is the
'nan'. In many languages, a nan is a 'polluting' variable i.e. once you
have a nan as a form anywhere in your calculation, the result will
always be a nan. Many languages actually have a special function to test
for a nan because it isn't actually a 'value'. Don't know if this is the
case with calc. 

Perhaps an alternative strategy might help. Could you address what is
generating the nan and change that so that it generates something else,
possibly even a blank string and avoid the nan altogether? 

--
Tim Cross



reply via email to

[Prev in Thread] Current Thread [Next in Thread]