Skip to content

Testing if all elements are equal in a vector/matrix

2 messages · Whit Armstrong, Vincent Goulet

#
or perhaps

length(unique(x))==1



-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Patrick Burns
Sent: Monday, August 29, 2005 5:22 PM
To: vincent.goulet at act.ulaval.ca
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] Testing if all elements are equal in a vector/matrix

How about

diff(range(x)) < tolerance

Patrick Burns
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")
Vincent Goulet wrote:

            
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
#
I like this one! It however has the same drawback as 

any(x == x[1])

Patrick Burn's suggestion is also quite nice and original and allows for some 
fuzzyness, like all.equal() does.

I will conclude from this thread that there is no canonical way to do the test 
I want, but many different approaches (something frequent in R). Thanks all 
for the suggestions!

Le 29 Ao??t 2005 17:45, vous avez ??crit??: