On Tue, Jun 03, 2008 at 10:37:33AM +1000, Jason Lee wrote:
> Hi,
> 
> If there are more than one item having the same value, how can i use R to
> take the average of the position. E.g:-
> 
>        X     Y     Z
> 131 22.2 3.4   4.4
> 132 20.0 3.4   4.4==>Position 2 if queried
> 150  20.0 12.2 4.5 =>Position 3 if queried
> 134 20.0 3.4   4.4 ==> Position4 if queried
> 159  20.0 12.2 4.5==>Position 5 if queried
> 160  22.0 12.2 4.5
> 
> When I query 150 using which, it gives "3" but since in other position the
> value are same which is 20.0, how can i get the average of the position
> which is (2+3+4+5)/3

aggregate() will do what you want. A little warning: of course aggregate
will group by elements which are EXACTLY the same so make sure the
floats in columns X really behave the way you want. Otherwise you may
want to have a look at cut().

cu
        Philipp

-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
 
 and
 
Institut für Bioinformatik und Systembiologie / MIPS
Helmholtz Zentrum München -
Deutsches Forschungszentrum für Gesundheit und Umwelt
Ingolstädter Landstrasse 1
85764 Neuherberg, Germany
http://mips.gsf.de/staff/pagel

______________________________________________
R-help@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.

Reply via email to