5

I am an English teacher who is profoundly not good at math, but I want to make some simple calculations with an org-mode table. I've tried reading online, but am afraid the explanations are just not simple enough.

With the following table, what formula would I put in the final boxes to calculate the average grade for "draft" and the average grade for "final"? (That is, to calculate the mean of column 2 and the mean of column 3.)

| item    | draft | final|
|---------+-------+------|
| plot    |   2   |   3  |
| grammar |   3   |   4  |
|---------+-------+------|
| grade   |   ?   |   ?  |

Will the table recalculate with C-c * if I change one of the grades?

Thank you, steven arntson

1 Answer 1

15

You need 2 things here:

  • The vmean function (stands for vector mean)
  • The references @I and @II which stand for the first and second horizontal lines in the table.

So, with the cursor on the draft average cell, type :=vmean(@I..@II) and then RET. This will add the formula tag at the bottom of the table and the result in the table. Repeat for the other column.

| item    | draft | final |
|---------+-------+-------|
| plot    | 2     | 3     |
| grammar | 3     | 4     |
|---------+-------+-------|
| grade   | 2.5   | 3.5   |
#+TBLFM: @4$2=vmean(@I..@II)::@4$3=vmean(@I..@II)

If you are going to have many columns, you can also have only 1 formula for all columns thus:

#+TBLFM: @4$2..@4$>=vmean(@I..@II)

This means that all cells in row 4, from column 2 to the last column (denoted by $>) will have the same formula. By not including column references in the vmean() expressions, it automatically refers to the same column.

If you want to round your averages to, say, 2 decimal digits, you may add a format modifier:

#+TBLFM: @4$2..@4$>=vmean(@I..@II);%.2f

In this case, the modifier says to display floating point (fractional) numbers, with 2 digits after the decimal point.

Documentation for references.

1
  • Thank you so much for taking the time to explain this. At the moment I only understand the beginning of your answer, but it works! I will come back and read through again later, and try to get my mind around the rest. Commented Dec 4, 2015 at 1:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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