emacs-orgmode
[Top][All Lists]
Advanced

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

Re: Two tables with same data but different sorting


From: Axel Kielhorn
Subject: Re: Two tables with same data but different sorting
Date: Mon, 5 Oct 2020 10:08:08 +0200


> Am 02.10.2020 um 11:36 schrieb Robert Pluim <rpluim@gmail.com>:
> 
>>>>>> On Fri, 2 Oct 2020 08:25:03 +0200, Axel Kielhorn 
>>>>>> <org-mode@axelkielhorn.de> said:
> 
>>> Am 01.10.2020 um 17:47 schrieb John Kitchin <jkitchin@andrew.cmu.edu>:
>>> 
>>> Glad it was helpful. You might also try (seventh row1) or (nth 6 row1). I 
>>> think it is the same thing, but more obvious to read!
> 
>    Axel> I agree that „first second …“ would be easier for an english speaker.
>    Axel> Having the ordinal number 1 based but the nth number 0 based is 
> irritating (and sadly there is no „last“ or „penultimate“).
> 
> ? C-h f last
> 
>    last is a compiled Lisp function in `subr.el'.
> 
>    (last LIST &optional N)
> 
>      Probably introduced at or before Emacs version 1.1.
>      This function does not change global state, including the match data.
> 
>    Return the last link of LIST.  Its car is the last element.
>    If LIST is nil, return nil.
>    If N is non-nil, return the Nth-to-last link of LIST.
>    If N is bigger than the length of LIST, return LIST.

As i understand it, this should work:

* Table

#+name: table1
| Manufacturer    | Name        | Price |
|-----------------+-------------+-------|
| ACME            | super cheep | 127 $ |
| Roadrunner Inc. | Kaboom      | 27 $  |
| ACME            | cheep       | 30 $  |

#+RESULTS: resorted
| Manufacturer    | Name        | Price |
|-----------------+-------------+-------|
| ACME            | super cheep | 127 $ |
| ACME            | cheep       | 30 $  |
| Roadrunner Inc. | Kaboom      | 27 $  |

** Code for resorting

#+name: resorted
#+BEGIN_SRC emacs-lisp :var data=table1 :colnames t
(sort data (lambda (row1 row2) (string< (last row1) (last row2))))
#+END_SRC

But I get:
Wrong type argument: stringp, ("30 $“)

Greeting Axel


reply via email to

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