[R] Mean of simulation runs given in a table

Ireneusz Szcześniak irek.szczesniak at gmail.com
Tue Jan 17 23:42:37 CET 2012


Thank you, Uwe, for your help!  I have more measurements (m1, m2) and 
more parameters (par1, par2).  I can calculate the means of m1 and m2 
this way:

aggregate(cbind(m1, m2) ~ par1 + par2, dat, mean)

However, I also need to calculate the standard error of the mean, and 
the variance for the sample, and I would like to have them output as 
extra columns next to the column with means.

Again, I would appreciate any help!

On 17.01.2012 15:09, Uwe Ligges wrote:
>
>
> 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.
>


-- 
Ireneusz (Irek) Szczesniak
http://www.irkos.org



More information about the R-help mailing list