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

Albyn Jones jones at reed.edu
Tue Nov 9 02:11:53 CET 2010


how about 

           all.equal(x,rep(mean(x),length(x)))
or

           all.equal(x,rep(mean(x),length(x), tolerance=...)

albyn

On Mon, Nov 08, 2010 at 06:45:00PM -0600, Hadley Wickham wrote:
> Hi all,
> 
> What's the equivalent to length(unique(x)) == 1 if want to ignore
> small floating point differences?  Should I look at diff(range(x)) or
> sd(x) or something else?  What cut off should I use?
> 
> If it helps to be explicit, I'm interested in detecting when a vector
> is constant for the purpose of visual display.  In other words, if I
> rescale x to [0, 1] do I have enough precision to get at least 100
> unique values.
> 
> Thanks!
> 
> Hadley
> 
> -- 
> Assistant Professor / Dobelman Family Junior Chair
> Department of Statistics / Rice University
> http://had.co.nz/
> 
> ______________________________________________
> R-help at 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.
> 

-- 
Albyn Jones
Reed College
jones at reed.edu



More information about the R-help mailing list