[R] How to detect if a vector is FP constant?

Hadley Wickham hadley at rice.edu
Tue Nov 9 04:05:35 CET 2010


> I think this does what you want (borrowing from all.equal.numeric):
>
> all(abs((x - mean(x))) < .Machine$double.eps^0.5)
>
> with a vector of length 1 million, it took .076 seconds on a fairly old system.

Hmmm, maybe I want:

all.equal(min(x), max(x))

?

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list