If I understand your question:

 x$IAC0 <- with(x, ave(IAC, list(ProfA, Key), FUN = mean))

On Wed, Apr 30, 2008 at 3:52 PM, Chip Barnaby <cbarnaby@wrightsoft.com>
wrote:

> Dear all --
>
> I have a data frame containing data related to heat gain through windows.
>  The general form is ...
>
> Key  ProfA    IAC   <many other numeric columns>
> AAA        0    .7
> AAA      10    .6
> AAA        0   .66
> AAA      20   .45
> (more AAA rows)
> (then AAB rows)
>
> 'Key' identifies the physical configuration ... rows with a given Key
> contain data for same window under various conditions.
>
> I want to add a column IAC0 containing, for each Key, the mean IAC of all
> rows with ProfA == 0.
>
> The general approach I think I need is approximately (the following is not
> known to run) --
>
> 1) XS<-subset( X, ProfA < .01) to get the ProfA == 0 rows.  This could be
> done implicitly as part of step 2, I suppose.
>
> 2) X0<-aggregate( XS[,"IAC"], by=list( Key=XS$Key), mean)
>
> 3) XF<-merge( X, X0, by="Key")
>
> 4) Change new col name to "IAC0" (see Question 2).
>
> Question 1: Is this a reasonable way to solve my problem?
>
> Question 2: The aggregate() result has 2 columns: "Key" and "x".   Can the
> name of the mean column be specified (short of renaming after the fact)?
>  All the aggregate() examples (e.g. in help()) elegantly produce the "right
> result" with nicely named columns etc.  I can't seem to make things work so
> smoothly.
>
> Thanks!
>
> Chip Barnaby
>
>
>
>
>
>
>
>
>
> ---------------------------------------------------------
> Chip Barnaby                   cbarnaby@wrightsoft.com
> Vice President of Research
> Wrightsoft Corp.               781-862-8719 x118 voice
> 131 Hartwell Ave               781-861-2058 fax
> Lexington, MA 02421         www.wrightsoft.com
>
> ______________________________________________
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]

