# [R] how to calculate the mean of a group in a table

From: tornanddesperate <MatthiasNeff_at_gmx.ch>
Date: Sat, 07 May 2011 11:24:18 -0700 (PDT)

Hi its me again

I don't mean to get on your nerves, but the use of R proofs to be a bit more complicated than envisaged.

I would like to calculate the mean of a group of values, here "wage_accepted". The group is determined by the stage and period, so in the end there should be a column with the values of the wages in period 1 stage1, period 1 stage 2, period 2 stage1... Unfortunately, I haven't much of a clue on how to program this. Could you tell me how the function should roughly look like – if-else, loops included or not – in the end ?

treatment session period stage wage_accepted type

```1          1       1      1     1            25  low
2          1       1      1     1            19  low
3          1       1      1     1            15  low
4          1       1      1     2            32 high
5          1       1      1     2            13  low
6          1       1      1     2            14  low
7          1       1      2     1            17  low
8          1       1      2     1            12  low

```

I am also very grateful if someone could point out a good internet tutorial resource for R functions such as if-else and loops and how to use them in conjunction with tables. It should contain simple examples if possible.

As ever indepted to you,

Matthias

```--
View this message in context: http://r.789695.n4.nabble.com/how-to-calculate-the-mean-of-a-group-in-a-table-tp3505986p3505986.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help