Re: [R] Need advise in grab the line number of sorted list in R

From: Philipp Pagel <p.pagel_at_wzw.tum.de>
Date: Tue, 03 Jun 2008 09:39:03 +0200

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_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.
Received on Tue 03 Jun 2008 - 07:51:53 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 03 Jun 2008 - 08:30:38 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive