From Kurt.Hornik at wu-wien.ac.at  Mon Aug 13 21:27:09 2007
From: Kurt.Hornik at wu-wien.ac.at (Kurt Hornik)
Date: Mon, 13 Aug 2007 21:27:09 +0200
Subject: [Rd] hasNA() / anyNA()?
In-Reply-To: <b02e8b330708131118g2efc7431k1318c43a87e1f467@mail.gmail.com>
References: <59d7961d0708131045x7feeeab5i4edf107350fbefdb@mail.gmail.com>
	<b02e8b330708131118g2efc7431k1318c43a87e1f467@mail.gmail.com>
Message-ID: <18112.45197.316066.610157@mithrandir.hornik.net>

>>>>> Michael Cassin writes:

> I don't know of one.

> Ideally, instead of a specifc function anyNA() function, any() could
> be perhaps be extended to any(x, FUN) where FUN returns a logical for
> an element of x, and implemented to find the 1st instance as you
> suggest.

Patterned after Common Lisp's position(), ideally we would have formals
(x, FUN, right = FALSE) where the last argument controls whether the
search proceeds from left to right or right to left.

This would certainly be very nice to have, and make it trivial to
provide an efficient variant of Common Lisp's find() (which finds the
first element from the left or right for which the predicate gives
true).

-k

> Mike

> On 8/13/07, Henrik Bengtsson <hb at stat.berkeley.edu> wrote:
>> 
>> Hi,
>> 
>> is there a hasNA() / an anyNA() function in R?  Of course,
>> 
>> hasNA <- function(x) {
>> any(is.na(x));
>> }
>> 
>> would do, but that would scan all elements in 'x' and then do the
>> test.  I'm looking for a more efficient implementation that returns
>> TRUE at the first NA, e.g.
>> 
>> hasNA <- function(x) {
>> for (kk in seq(along=x)) {
>> if (is.na(x[kk]))
>> return(TRUE);
>> }
>> FALSE;
>> }
>> 
>> Cheers
>> 
>> Henrik
>> 
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>> 

> 	[[alternative HTML version deleted]]

> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] hasNA() / anyNA()?
Kurt Hornik