Re: [R] "with" and "by" and NA:

2009-03-25 Thread Duncan Murdoch
On 25/03/2009 7:36 PM, Aldi Kraja wrote: Hi, I have a data.frame with many variables for which I am performing the mean by subgroup, for a pair of variables at a time, where one of them for each pair defines the subgroup. The subgroups in the x$cm1 are 0, 1 and 2. x ph1 cm1 0.2345 2 1. 1

Re: [R] "with" and "by" and NA:

2009-03-25 Thread Jorge Ivan Velez
Dear Aldi, Yes . Here it is: as.vector(with(x, by(ph1, cm1, mean,na.rm=TRUE))) or with(x,tapply(phi1,cm1,mean,na.rm=TRUE)) See ?mean and ?tapply for more details. HTH, Jorge On Wed, Mar 25, 2009 at 7:36 PM, Aldi Kraja wrote: > Hi, > > I have a data.frame with many variables for which I

[R] "with" and "by" and NA:

2009-03-25 Thread Aldi Kraja
Hi, I have a data.frame with many variables for which I am performing the mean by subgroup, for a pair of variables at a time, where one of them for each pair defines the subgroup. The subgroups in the x$cm1 are 0, 1 and 2. x ph1 cm1 0.2345 2 1. 1 2.0033 0 0. 2 1.0033 1 0.2345 0 1.222