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) in contrast ...>na.omit(c(1,2,3,NA))[1] 1 2 3 attr(,"na.action") [1] 4 attr(,"na.action")attr(,"class") [1] "omit" Thanks, Alex --------------------------- platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 1 minor 1.0 year 2000 month June day 15 language R -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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)Well, because there is a bug in na.omit.default. The problem is in the section of code omit <- seq(along = object)[is.na(object)] nm <- names(object) object <- object[-omit] If there are no NA's in the object, then omit becomes a length 0 vector and -omit doesn't have the intended effect. A temporary fix would be to insert if (length(omit) == 0) return(object) after the first line shown above. We'll incorporate a fix for the next release. Thanks for reporting the bug.> --------------------------- > platform i686-pc-linux-gnu > arch i686 > os linux-gnu > system i686, linux-gnu > status > major 1 > minor 1.0 > year 2000 > month June > day 15 > language R > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-- Douglas Bates bates at stat.wisc.edu Statistics Department 608/262-2598 University of Wisconsin - Madison http://www.stat.wisc.edu/~bates/ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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) But of course, I have no clue as to what that would break.... :-) Best, Kjetil -- Kjetil Kjernsmo Graduate astronomy-student Problems worthy of attack University of Oslo, Norway Prove their worth by hitting back E-mail: kjetikj at astro.uio.no - Piet Hein Homepage <URL:http://www.astro.uio.no/~kjetikj/> Webmaster at skepsis.no -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._