RE: [R] how calculate mean for each group

2003-10-02 Thread kjetil brinchmann halvorsen
On 2 Oct 2003 at 16:11, Simon Fear wrote: > > (BTW did I ever mention here how much I prefer with() to > attach()/forget.to.detach() ?) > Agreed. I learnt about with() a few weeks ago and hasn't used attach()/forget to detach() since. Kjetil Halvorsen __

RE: [R] how calculate mean for each group

2003-10-02 Thread Marc Schwartz
On Thu, 2003-10-02 at 10:11, Simon Fear wrote: > A little more succinctly and I hope also helpful: > > > with(df, aggregate(list(mean=treatment), > list(group = group, duplicate = duplicate), mean)) > > Note that the name of the summary of treatment is likely > best to be different from the

RE: [R] how calculate mean for each group

2003-10-02 Thread Simon Fear
A little more succinctly and I hope also helpful: > with(df, aggregate(list(mean=treatment), list(group = group, duplicate = duplicate), mean)) Note that the name of the summary of treatment is likely best to be different from the name of the treatment variable itself. It is tempting to do

Re: [R] how calculate mean for each group

2003-10-02 Thread Marc Schwartz
On Thu, 2003-10-02 at 08:47, Spencer Graves wrote: > An alternative to renaming columns in the ouput of aggregate is to > provide names in the "by" list as follows: > > aggregate(df$treatment, list(gp=df$group, dup=df$duplicate), mean) > > hope this helps. spencer graves SNIP Spencer, Yeah,

Re: [R] how calculate mean for each group

2003-10-02 Thread Spencer Graves
An alternative to renaming columns in the ouput of aggregate is to provide names in the "by" list as follows: aggregate(df$treatment, list(gp=df$group, dup=df$duplicate), mean) hope this helps. spencer graves Marc Schwartz wrote: On Wed, 2003-10-01 at 20:15, [EMAIL PROTECTED] wrote: Hello

Re: [R] how calculate mean for each group

2003-10-01 Thread Marc Schwartz
On Wed, 2003-10-01 at 20:15, [EMAIL PROTECTED] wrote: > Hello, R experts: > I got data like this: > group duplicate treatment > A Y 5 > A Y 3 > A N 6 > B Y 2 > B N 4 > B Y 1 > How to sort the

Re: [R] how calculate mean for each group

2003-10-01 Thread Spencer Graves
Have you considered "aggregate"? hope this helps. spencer graves [EMAIL PROTECTED] wrote: Hello, R experts: I got data like this: group duplicate treatment A Y 5 A Y 3 A N 6 B Y 2 B N 4 B Y

[R] how calculate mean for each group

2003-10-01 Thread szhan
Hello, R experts: I got data like this: group duplicate treatment A Y 5 A Y 3 A N 6 B Y 2 B N 4 B Y 1 How to sort the data and calculate the average treatment value for each group in two leve