s-news
[Top] [All Lists]

Re: Averaging rows

To: "Khan, Sohail" <khan@cshl.edu>
Subject: Re: Averaging rows
From: Tim Hesterberg <timh@insightful.com>
Date: 12 Dec 2005 14:50:06 -0800
Cc: <s-news@lists.biostat.wustl.edu>
In-reply-to: <C8696843AE995F4EA4CDC3E2B83482A90DDD91@mailbox02.cshl.edu> (khan@cshl.edu)
References: <C8696843AE995F4EA4CDC3E2B83482A90DDD91@mailbox02.cshl.edu>
Try the function groupMeans() from the S+Resample library.
Download info below.

That computes all group means; you could then subscript to get only
the rows that had repeated values of ID; e.g.
        groupMeans(x)[ unique(x$ID[duplicated(x$ID)]), ]

>I have data frame as follows:
>
>ID    ratio_1     ratio_2
>X      2.5          2.0 
>Y      3.6          2.1
>Y      2.9          1.2
>Y      3.5          4.2
>Z      2.5           1.9
>K      0.5           2.1
>L       1.4          4.1
>
>I would like average values of columns ratio_1, ratio_2 for all the IDs with 
>multiple values, i.e. ID Y would have average ratio_1 = 3.3333, ratio_2.5.
>I am a novice S_PLUS user, sorry for the trivial question. Thanks. 
>
>Sohail Khan
>Scientific Programmer
>COLD SPRING HARBOR LABORATORY
>Genome Research Center
>500 Sunnyside Boulevard
>Woodbury, NY 11797
>(516)422-4076

========================================================
| Tim Hesterberg       Research Scientist              |
| timh@insightful.com  Insightful Corp.                |
| (206)802-2319        1700 Westlake Ave. N, Suite 500 |
| (206)283-8691 (fax)  Seattle, WA 98109-3012, U.S.A.  |
|                      www.insightful.com/Hesterberg   |
========================================================
Download the S+Resample library from www.insightful.com/downloads/libraries

Two Research Scientist positions:
        data mining
        frailty/mixed effects
    http://www.insightful.com/company/jobs.asp

Speak out about biased science in Washington D.C.
    http://home.comcast.net/~timhesterberg/ScientificIntegrity.html


<Prev in Thread] Current Thread [Next in Thread>