[R] tapply and empty subsets

Patrick Connolly p.connolly at hortresearch.co.nz
Wed May 15 04:23:04 CEST 2002


On Tue, 14-May-2002 at 11:13PM +0000, jasont at indigoindustrial.co.nz wrote:
|> > I guess for my purpose the following will do.
|> > 
|> > > x <- tapply(y, z, mean)
|> > > x[is.na(x)] <- 0
|> > 
|> > Thanks,
|> > Giovanni
|> 

|> If I might ask, what's wrong with NA?  I occasionally deal with
|> data sets that do have means close to zero, so my doing this would
|> be misleading at best (YMMV).  NA is a good thing, for me.

Well, I've had occasions where NA was really zero.  Depends on what
sort of data you have and who entered it in whatever form it was done.
A control reading that can be safely assumed to be zero is an example
that comes to mind.

|> 
|> If you just can't live with NA, na.omit(tapply(y,z,mean)) might be more 
|> appropriate here.

Think that will end up with only two, and we need to know which of the
three is missing (and isn't really NA).

best

-- 
Patrick Connolly
HortResearch
Mt Albert
Auckland
New Zealand 
Ph: +64-9 815 4200 x 7188
~~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~
I have the world' s largest collection of seashells. I keep it on all
the beaches of the world ... Perhaps you've seen it.  ---Steven Wright
~~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~


______________________________________________________
The contents of this e-mail are privileged and/or confidential to the
named recipient and are not to be used by any other person and/or
organisation. If you have received this e-mail in error, please notify 
the sender and delete all material pertaining to this e-mail.
______________________________________________________

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list