[R] Mean of simulation runs given in a table

Uwe Ligges ligges at statistik.tu-dortmund.de
Tue Jan 17 15:09:18 CET 2012



On 17.01.2012 12:31, Irek Szczesniak wrote:
> Hi,
>
> I have the simulation results of the following structure:
>
> run par   measured
> 1   10    12
> 2   10    14
> 1   20    20
> 2   20    26
>
> Where "run" is the simulation run number, "par" is the parameter of
> the simulation, and "measured" is the value measured in the
> simulation.  This is only a simple example of my results.  There are
> many values measured and many parameters.  But the basic structure
> stays the same: there are many runs (identified by the run number) for
> the same values of the parameters with various measured values -- they
> constitute a sample.
>
> I would like to calculate the mean of the "measured" value for a
> sample, and so I would like to obtain the output as follows:
>
> par mean
> 10  13
> 20  23
>
> I would appreciate it if someone could write me how to do it.


For you data in a data.frame called dat:

aggregate(measured ~ par, dat, mean)

Uwe Ligges


>
> Thank you,
> Irek
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list