# Org table: aggregate each column (but not the header column)

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?

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.

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.

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 |

#+Begin_src python
return [[val + 10 for val in row] for row in tab]
#+end_src

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