On 7 April 2010 16:12, Steve Lianoglou <mailinglist.honey...@gmail.com> wrote:
> Hi,
>
> On Wed, Apr 7, 2010 at 5:44 PM, Robin Evans <rj...@stat.washington.edu> wrote:
>> Dear all,
>>
>> I'm wondering if there exist vectorized forms of 'isTRUE()',
>> 'identical()' and 'all.equal()'.  My problem is that I wish to test if
>> each element of a vector is equal to a particular value (or
>> numerically close), whilst dealing carefully with NAs and so on.
>> However, using sapply() with identical() is very slow because it makes
>> so many separate function calls:
>>
>> x = rbinom(1e4, 1, 0.5)
>>
>> system.time(sapply(x, function(x) isTRUE(all.equal(x, 0))))
>>
>> system.time(abs(x)  < .Machine$double.eps^0.5)
>>
>> The latter version is fast, but potentially dangerous.  Any suggestions?
>
> Why is it dangerous? Because some values in x can be NA?
>
Precisely - I would like all the answers to be TRUE or FALSE.

Rob
-- 
Robin Evans
Statistics Department
University of Washington
www.stat.washington.edu/~rje42

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to