[R] average among one factor in a nested dataframe
Junqian Gordon Xu
xjqian at gmail.com
Mon Apr 25 13:30:57 CEST 2011
Never mind, I find a generic solution:
which collapses away "f2", and it's easy to generalize this to collapse
On 4/25/11 6:14 AM, Kenneth Roy Cabrera Torres wrote:
> Hi Junquian:
> I try your code (there is a typo, I believe)
> But I don't understand the "nested" databases.
> I see that both have f1 variable but I do not see f2 variable in any of
> them. So, what do you mean with "collapse f2"?
> Maybe you need to first "merge()" de databases and then "aggregate()"
> Have a nice day!
> El dom, 24-04-2011 a las 23:42 -0500, Junqian Gordon Xu escribió:
>> I have two nested data frames:
>> I want to preserve id and f1, but want to collapse f2 and take the
>> corresponding mean values of a and b. Missing value in either dataframe
>> should be handled properly (i.e., just take the non-missing number
>> without dividing by 2).
>> I had a look at rowSum/Means and s/l/tapply, but couldn't figure out how
>> to handle this case cleanly. Any suggestions?
>> R-help at r-project.org mailing list
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help