[R] column statistics

Henrique Dallazuanna wwwhsd at gmail.com
Mon Dec 7 12:03:42 CET 2009


Use aggregate:

aggregate(x['Value'], x[c('Factor1', 'Factor2')], mean)



On Mon, Dec 7, 2009 at 8:25 AM, Ivan Calandra
<ivan.calandra at uni-hamburg.de> wrote:
> Hi everybody,
>
> I would like to compute the mean for 1 variable between the rows with the
> same levels.
>
> For example, with the dataset below:
> Factor1      Factor2      Value
> A               X               1
> A               X               2
> A               Y               3
> A               Y               4
> B               X               5
> B               X               6
> B               Y               7
> B               Y               8
>
> I would like to get:
> Factor1      Factor2      Value
> A               X               1.5
> A               Y               3.5
> B               X               5.5
> B               Y               7.5
>
> Up to now, I worked in Statistica and Systat, and it was called "column
> statistics" in Statistica (and I had a script with the "BY" function in
> Systat).
>
> Of course it is a simplified case. For my dataset I have 4 factors and 15
> variables, so a general method would be nice. However, my skills are not
> that great, so if you could please give some explanations (I mean other than
> what is in the ?function of course).
>
> Thanks a lot in advance
> Ivan
>
> ______________________________________________
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O




More information about the R-help mailing list