s-news
[Top] [All Lists]

Re: Calculating Averages for several combinations

To: "Bert Jacobs" <b.jacobs@pandora.be>
Subject: Re: Calculating Averages for several combinations
From: Tim Hesterberg <timh@insightful.com>
Date: 26 Jan 2006 11:20:23 -0800
Cc: <s-news@lists.biostat.wustl.edu>
In-reply-to: <20060126122443.9DF4438135@adicia.telenet-ops.be> (b.jacobs@pandora.be)
References: <20060126122443.9DF4438135@adicia.telenet-ops.be>
One approach:
        groupMeans(data[1:60],
                   paste(data$a, data$b, data$c, data$d))
assuming the continuous variables are in columns 1 to 60 and
categorical variables named a, b, c, d.  This would not give
averages for combinations that are missing.

groupMeans requires the resample library, see below.

>Using Splus 6,2 for Windows.
>
>Hello,
>
>I have a dataframe with 4 categorical variables and 60 continuous variables.
>Now I would like to calculate the averages of the 60 continuous variables
>for all possible combinations of the 4 categorical variables (with resp.
>13,3,58,23 levels).
>
>Is this possible in one equation or do I have to use the aggregate function
>16 times for every possible variable combination 
>
>Any ideas?
>
>Thx
>Bert

========================================================
| 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


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