Re: [R] Aggregate() questions

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Wed, 30 Apr 2008 16:09:01 -0300

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_at_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_at_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_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.
>

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

	[[alternative HTML version deleted]]


______________________________________________ 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 Wed 30 Apr 2008 - 19:43:38 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 Wed 30 Apr 2008 - 20:31:39 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