3

I would like to transpose this table example from Org as a spreadsheet system: a short introduction:

| Student  | Maths | Physics | Mean |
|----------+-------+---------+------|
| Bertrand |    13 |      09 |   11 |
| Henri    |    15 |      14 | 14.5 |
| Arnold   |    17 |      13 |   15 |
#+TBLFM: $4=vmean($2..$3)

This part is easy:

| Student | Bertrand | Henri | Arnold |
| Maths   |       13 |    15 |     17 |
| Physics |       09 |    14 |     13 |
| Total   |          |       |        |
#+TBLFM: @4=vmean(@2..@3)

But after a full recalculation (C-u C-c C-c), the text (Maths + Physics) / 2 is inserted:

| Student               | Bertrand | Henri | Arnold |
| Maths                 |       13 |    15 |     17 |
| Physics               |       09 |    14 |     13 |
| (Maths + Physics) / 2 |       11 |  14.5 |     15 |
#+TBLFM: @4=vmean(@2..@3)

How do I treat the first column as a header column? I think this would solve the problem.

Update 2014-01-07 6:26 PM EST: The two answers (by Juanco and wvxvw) work, but is there a way to solve this without changing the formula line at all? Is there a way to tell Org mode that the leftmost column is a header column?

7

You can specify the target cells for the formula to avoid overwriting the first column.

One way is the following:

#+TBLFM: @4$<<..@4$>=vmean(@2..@3)

Where $<< refers to the second column, and $> to the last.

3

You also need to specify the range on the left hand side:

| Student | Bertrand | Henri | Arnold |
|---------+----------+-------+--------|
| Maths   |       13 |    15 |     17 |
| Physics |       09 |    14 |     13 |
|---------+----------+-------+--------|
| Total   |       11 |  14.5 |     15 |
#+TBLFM: @4$2..@$4=vmean(@2..@3)

If I understood you correctly.

2

If I understand your questions & concerns correctly, you want to:

  1. Transpose an org-mode table
  2. Use the #+TBLFM: @4=vmean(@2..@3) formula but this
    overwrites the word Total with (Maths + Physics) / 2 which is unacceptable.
  3. Leave the #+TBLFM: @4=vmean(@2..@3) line as-is but have org-mode ignore first column in the table when applying the formula.

There is feature that will instructs org-mode to ignore the first column, :rownames, or first row, :colnames, of a table when performing calculations. Unfortunately, you will need to pass the table into code block.

Simple example demonstrating :rownames and :colnames headers on a code block.

#+NAME: ex-rownames-colnames
|   | C |  D |
|---+---+----|
| A | 2 |  9 |
| B | 4 | 16 |

#+name: add-ten-to-table
#+header: :colnames yes 
#+header: :rownames yes
#+header: :var tab=ex-rownames-colnames
#+Begin_src python
   return [[val + 10 for val in row] for row in tab]
#+end_src

#+RESULTS: add-ten-to-table
|   |  C |  D |
|---+----+----|
| A | 12 | 19 |
| B | 14 | 26 |

Using this method to solve your total display issue is probably overkill.

The simplest solution is to modify #+TBLFM: @4=vmean(@2..@3) as Juanco or wvxvw suggested.

Hope that helped.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.