[R] new R-user needs help

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.be
Wed Oct 18 11:26:59 CEST 2006


try something like the following:

sapply(split(dat[paste("x", 1:5, sep = "")], dat$name), mean)


Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: <antoniababe at yahoo.se>
To: <r-help at stat.math.ethz.ch>
Sent: Wednesday, October 18, 2006 11:10 AM
Subject: [R] new R-user needs help


> Dear all,
>
> I have a dataset
>
> Exp name id x1 x2 x3 x4 x5
> 1   a    1  23 24 23 22 30
> 1   b    2  25 26 27 23 24
> 1   c    3  32 19 23 25 28
> 2   a    4  28 32 24 26 27
> 2   b    5  23 24 25 26 28
> 2   c    6  23 31 30 38 23
> 3   a    7  24 25 31 27 29
> 3   b    8  28 25 26 32 28
> 3   c    9  21 31 28 23 29
>
> where each name a,b and c is repeated three times.
> Now I want to calculate the the averages of a,b and c
> over the three experiments for each x. For example for
> x1 I want to calculate the average of a like
>
> [a(from exp1) + a(exp2)+ a(exp3)]/3= (23+28+24)/3
>
> How can I do that ?
>
> Thanks for your help,
> Regards,
>
> Antonia
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



More information about the R-help mailing list