Skip to content

Table manipulation

Giorgio Garofalo edited this page Apr 25, 2025 · 4 revisions

The following table operations can affect not only plain Markdown tables, but also any kind of table including those loaded from CSV.

CSV example
.tablesort {2} order:{descending}
    .csv {people.csv}

Sort rows

The .tablesort function sorts a table based on the values of a specific column.

Parameter Description Accepts
column Index of the column, starting from 1. 1 to number of columns.
order Sorting order. ascending (default), descending
.tablesort {2} order:{descending}
    | Name | Age | City |
    |------|-----|------|
    | John | 25  | NY   |
    | Lisa | 32  | LA   |
    | Mike | 19  | CHI  |

Result:

| Name | Age | City |
|------|-----|------|
| Lisa | 32  | LA   |
| John | 25  | NY   |
| Mike | 19  | CHI  |

 

Filter rows

The .tablefilter function keeps or removes rows based on the values of a specific column.

Parameter Description Accepts
column Index of the column, starting from 1. 1 to number of columns.
filter Lambda that returns whether each row should be kept, with the value of its cell in the corresponding column as input. DynamicBoolean lambda
.tablefilter {2} {@lambda x: .x::isgreater {20}}
    | Name | Age | City |
    |------|-----|------|
    | John | 25  | NY   |
    | Lisa | 32  | LA   |
    | Mike | 19  | CHI  |

Result:

| Name | Age | City |
|------|-----|------|
| John | 25  | NY   |
| Lisa | 32  | LA   |

 

Compute/aggregate columns

The .tablecompute function computes the cells in a column and appends the result to a new row.

Parameter Description Accepts
column Index of the column, starting from 1. 1 to number of columns.
compute Lambda that returns the computed value, with the collection of the cells in the column as input. IterableDynamic lambda

See Iterable to learn more about available operations on collections.

Example:

.tablecompute {2} {@lambda x: .x::average::round}
    | Name | Age | City |
    |------|-----|------|
    | John | 25  | NY   |
    | Lisa | 32  | LA   |
    | Mike | 19  | CHI  |

Result:

| Name | Age | City |
|------|-----|------|
| John | 25  | NY   |
| Lisa | 32  | LA   |
| Mike | 19  | CHI  |
|      | 25  |      |

 

Composition

Multiple table operations can be chained. The order of the operations goes from inner to outer:

.tablecompute {2} {@lambda x: .x::average::round}
    .tablesort {2}
        | Name | Age | City |
        |------|-----|------|
        | John | 25  | NY   |
        | Lisa | 32  | LA   |
        | Mike | 19  | CHI  |

Result:

| Name | Age | City |
|------|-----|------|
| Mike | 19  | CHI  |
| John | 25  | NY   |
| Lisa | 32  | LA   |
|      | 25  |      |

 

Retrieve columns

The .tablecolumn function extracts values from the cells of a specific column, and returns them as an Iterable.

Parameter Description Accepts
column Index of the column, starting from 1. 1 to number of columns.
.var {values}
    .tablecolumn {2}
        | Name | Age | City |
        |------|-----|------|
        | John | 25  | NY   |
        | Lisa | 32  | LA   |
        | Mike | 19  | CHI  |

.values::first

Result: 25

 

Additionally, the .tablecolumns function returns all the columns from the table, as an iterable of iterables. This is more efficient in case you need to access multiple columns from the same table.

.var {columns}
    .tablecolumn
        | Name | Age | City |
        |------|-----|------|
        | John | 25  | NY   |
        | Lisa | 32  | LA   |
        | Mike | 19  | CHI  |

.foreach {.columns}
  col:
  .col::first

Result:

John
25
NY

Getting started [NEW!]

Documentation

CLI tools

Markdown enhancements

Functions

Setting up

Multi-file projects

Layout

Charts & diagrams

Scripting & control flow

Utilities

Slides

I/O

Native content

Value types

Built-in libraries

  • Paper: abstract, definitions, theorems, and more

Extra features

Inside Quarkdown

Clone this wiki locally