[R] na.omit

Prof Brian D Ripley ripley at stats.ox.ac.uk
Mon Jul 17 23:26:12 CEST 2000


On Mon, 17 Jul 2000, Kjetil Kjernsmo wrote:

> On 17 Jul 2000, Douglas Bates wrote:
> 
> >buerkle at hawaii.edu writes:
> >
> >> Why is it that when a vector contains no NAs, na.omit returns an empty
> >> vector rather than the object/vector that was passed to it?  
> >> 
> >> >na.omit(c(1,2,3,4))          
> >> numeric(0)
> 
> I have been wondering about something that could be related (perhaps not),
> whether it is a design choice or a bug. If you do:
> > 1:numeric(0)
> Error in 1:numeric(0) : NA/NaN argument
> In some cases, it has seemed to me that it would have been sooo much more
> convenient if it returned
> numeric(0)

Why is that a sensible answer?  1:x expects a length-one vector x,
preferably an integer one.  And 1:0, for example, is not a length-zero
vector.  If x is not specified, 1:x is also not specified.  In particular,
its length is not specified (and hence not specified as zero) and so
a vector of NAs will not do.

If you really, really wanted this it should be integer(0) for consistency.
(1:n has storage mode integer.)

> But of course, I have no clue as to what that would break.... :-)

Interpretability!

S does try to do sensible things in boundary cases (in the Unix tradition),
but only where (almost) everyone can agree on what is sensible.

BTW, ?seq does not specify the arguments, so I had better fix that.


-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

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