emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* how to concatenate string to spreadsheet formula
@ 2022-08-15 13:50 edgar
  2022-08-15 14:40 ` Fraga, Eric
  0 siblings, 1 reply; 3+ messages in thread
From: edgar @ 2022-08-15 13:50 UTC (permalink / raw)
  To: emacs-orgmode

Dear everyone,

At the moment, I am using an Org spreadsheet to concatenate a string  
to the ratio between 2 numbers. One of numbers is the  
[[sum-of-column][sum of a column]]. The other number would correspond  
to [[each-row-col1][each of the rows of another column]]  
([[ratio-to-0.95][multiplied by a factor]])
1. <<sum-of-column>>calculate the sum of a column
    - originally wanted vsum
    - corresponding part: =(reduce '+ (mapcar 'string-to-number (list  
@5$<..@6$<)))=
2. <<each-row-col1>>each of the values in column 1
    (string-to-number $1)
3. <<ratio-to-0.95>>the ratio between [[each-row-col1]] and  
[[sum-of-column]] is multiplied by 0.95

The final value is concatenated with "\\textwidth".

| width | height |      w / Σw |                   w / pic_row |
|   204 |    120 |  0.10418795 |                    0.32606557 |
|   215 |    125 |  0.10980592 |                    0.34364754 |
|   191 |    119 | 0.097548519 |                    0.30528689 |
|   483 |    125 |  0.24668029 |  0.7294912559614499\textwidth |
|   146 |    128 | 0.074565884 | 0.22050874403854998\textwidth |
|   719 |    101 |  0.36721144 |                               |
|-------+--------+-------------+-------------------------------|
|  1958 |    718 |             |                               |
#+tblfm: @5$4..@6$4='(concat (number-to-string (* 0.95  
(string-to-number (math-format-number (math-div (string-to-number $1)  
(reduce '+ (mapcar 'string-to-number (list @5$<..@6$<))))))))  
"\\textwidth")

Is there a more succint way of doing this? For instance, my original  
intention was to have something like

     #+tblfm: @5$4..@6$4=vsum($1 / vsum(@5$<..@6$<);"%0.4f\\textwidth"

which does not work. I would also like to avoid creating another  
column (=#+tblfm: @5$4..@6$4=vsum($1 /  
vsum(@5$<..@6$<);%0.4f::@<<$5..@>>$5='(concat $4 "\\textwidth")=).

Thank you very much!


-------------------------------------------------
This free account was provided by VFEmail.net - report spam to abuse@vfemail.net
 
ONLY AT VFEmail! - Use our Metadata Mitigator to keep your email out of the NSA's hands!
$24.95 ONETIME Lifetime accounts with Privacy Features!  
15GB disk! No bandwidth quotas!
Commercial and Bulk Mail Options!  


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how to concatenate string to spreadsheet formula
  2022-08-15 13:50 how to concatenate string to spreadsheet formula edgar
@ 2022-08-15 14:40 ` Fraga, Eric
  2022-08-16  8:22   ` edgar
  0 siblings, 1 reply; 3+ messages in thread
From: Fraga, Eric @ 2022-08-15 14:40 UTC (permalink / raw)
  To: edgar@openmail.cc; +Cc: emacs-orgmode@gnu.org

Hi Edgar,

I did not quite understand what you actually were calculating but maybe
consider the following expression for table formulas:

#+TBLFM: $3='(format "%s\\textwidth" (/ (* 1.0 $2) $1));N

If you specify ";N", the entries are treated as numbers.  The problem
with division is that if both numbers are integers, integer division is
used so I multiply one of the arguments by 1.0 to ensure floating point
numbers.

HTH,
eric

-- 
: Eric S Fraga, with org release_9.5.4-720-g4db67d in Emacs 29.0.50

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how to concatenate string to spreadsheet formula
  2022-08-15 14:40 ` Fraga, Eric
@ 2022-08-16  8:22   ` edgar
  0 siblings, 0 replies; 3+ messages in thread
From: edgar @ 2022-08-16  8:22 UTC (permalink / raw)
  To: Org Mode List

On 2022-08-15 14:40, Fraga, Eric wrote:
> Hi Edgar,
> 
> I did not quite understand what you actually were calculating but maybe
> consider the following expression for table formulas:
> 
> #+TBLFM: $3='(format "%s\\textwidth" (/ (* 1.0 $2) $1));N
> 
> If you specify ";N", the entries are treated as numbers.  The problem
> with division is that if both numbers are integers, integer division is
> used so I multiply one of the arguments by 1.0 to ensure floating point
> numbers.
> 
> HTH,
> eric

Aha! Thank you very much.

-------------------------------------------------
This free account was provided by VFEmail.net - report spam to abuse@vfemail.net
 
ONLY AT VFEmail! - Use our Metadata Mitigator to keep your email out of the NSA's hands!
$24.95 ONETIME Lifetime accounts with Privacy Features!  
15GB disk! No bandwidth quotas!
Commercial and Bulk Mail Options!  


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-16  8:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-15 13:50 how to concatenate string to spreadsheet formula edgar
2022-08-15 14:40 ` Fraga, Eric
2022-08-16  8:22   ` edgar

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).