5

I am a beginner at org-tables, trying to use them for computing grades in a class I'm teaching. I have a table showing attendance records for a student, resulting in a mean that I'd like to use in a calculation in another table. Is it possible?

#+NAME: attendance
| time   | grade            |
|--------+------------------|
| week 1 | 1                |
| week 2 | 0                |
| week 3 | 1                |
|--------+------------------|
| grade  | :=vmean(@I..@-I) |

#+NAME: grades
| assignment | grade                            |
|------------+----------------------------------|
| attendance | [INSERT VMEAN FROM "attendance"] |
| paper 1    | 2.5                              |
| paper 2    | 2.5                              |
|------------+----------------------------------|
| final grade| :=vmean(@I..@-I)                 |

1 Answer 1

7

At the end of section 3.5.1 of org manual there's a discussion of remote references, that's exactly what you're looking for:

You may also reference constants, fields and ranges from a different table, either in the current file or even in a different file. The syntax is

remote(NAME-OR-ID,REF)

where NAME can be the name of a table in the current file as set by a ‘#+NAME: Name’ line before the table.

Here, you should simply name your first table and enter a formula using the remote reference in the chosen cell, :=remote(attendance,@5$2).

#+NAME: attendance
| time   | grade |
|--------+-------|
| week 1 |     1 |
| week 2 |     4 |
| week 3 |     2 |
|--------+-------|
| grade  |     2 |
#+TBLFM: @5$2=vmean(@I..@-I)

#+NAME: grades
| assignment  |     grade |
|-------------+-----------|
| attendance  |         2 |
| paper 1     |       2.5 |
| paper 2     |       2.5 |
|-------------+-----------|
| final grade | 2.3333333 |
#+TBLFM: @2$2=remote(attendance,@5$2)::@5$2=vmean(@I..@-I)

To update the tables, use M-x org-table-recalculate-buffer-tables or M-x org-table-iterate-buffer-tables if you set up complex table dependencies.

Note that in this particular case, it's certainly better to use @>$2 (last line, column 2): the @5$2 won't be updated automatically in the 'grades' table if you later add lines to the 'attendance' table. Another, more general, way to avoid this kind of problem is to use named references. Here, we name the cell grade so that we can reference it as $grade.

#+NAME: attendance2
|   | time   | grade |
|---+--------+-------|
|   | week 1 |     1 |
|   | week 2 |     4 |
|   | week 3 |     1 |
|---+--------+-------|
|   | grade  |     2 |
| ^ |        | grade |
#+TBLFM: @5$3=vmean(@I..@-I)

#+NAME: grades2
| assignment  |     grade |
|-------------+-----------|
| attendance  |         2 |
| paper 1     |       2.5 |
| paper 2     |       2.5 |
|-------------+-----------|
| final grade | 2.3333333 |
#+TBLFM: @2$2=remote(attendance2,$grade)::@5$2=vmean(@I..@-I)
5
  • Thank you for this. I've refined the question above based on your advice here ... I hope that isn't considered impolite (I'm somewhat new to Stack Exchange). Dec 7, 2015 at 1:56
  • 1
    @StevenArntson I expanded my answer to include details. If this solves your problem I suggest you revert your question to its first revision so that question and answer "agree".
    – JeanPierre
    Dec 7, 2015 at 10:21
  • Thank you. One part of the problem ended up being that I hadn't put := before remote(...). It is now working well! Dec 8, 2015 at 17:13
  • 1
    @StevenArntson Beware if you later add lines to the 'grades' table. I added info on how to avoid such problems.
    – JeanPierre
    Dec 11, 2015 at 16:54
  • Using named references is going to be very useful for me, thank you. Dec 22, 2015 at 17:37

Your Answer

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

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