Re: [R] Testing if all elements are equal in a vector/matrix

2005-08-30 Thread Robin Hankin
Hi

library(magic)
?minmax


[
the basic idea is min(x) == max(x)
]


best wishes


Robin
On 29 Aug 2005, at 20:35, Vincent Goulet wrote:


 Is there a canonical way to check if all elements of a vector or  
 matrix are
 the same? Solutions below work, but look hackish to me.


 x - rep(1, 10)
 all(x == x[1])  # == operator does not provide for small differences

 [1] TRUE

 isTRUE(all.equal(x, rep(x[1], length(x # ugly

 [1] TRUE

 Best,

 Vincent
 -- 
   Vincent Goulet, Associate Professor
   École d'actuariat
   Université Laval, Québec
   [EMAIL PROTECTED]   http://vgoulet.act.ulaval.ca

 __
 R-help@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


--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-help@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


[R] Testing if all elements are equal in a vector/matrix

2005-08-29 Thread Vincent Goulet

Is there a canonical way to check if all elements of a vector or matrix are 
the same? Solutions below work, but look hackish to me.

 x - rep(1, 10)
 all(x == x[1])  # == operator does not provide for small differences
[1] TRUE
 isTRUE(all.equal(x, rep(x[1], length(x # ugly
[1] TRUE

Best,

Vincent
-- 
  Vincent Goulet, Associate Professor
  École d'actuariat
  Université Laval, Québec 
  [EMAIL PROTECTED]   http://vgoulet.act.ulaval.ca

__
R-help@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


Re: [R] Testing if all elements are equal in a vector/matrix

2005-08-29 Thread Doran, Harold
See ?identical 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Vincent Goulet
Sent: Monday, August 29, 2005 3:35 PM
To: r-help@stat.math.ethz.ch
Subject: [R] Testing if all elements are equal in a vector/matrix


Is there a canonical way to check if all elements of a vector or matrix are the 
same? Solutions below work, but look hackish to me.

 x - rep(1, 10)
 all(x == x[1])  # == operator does not provide for small differences
[1] TRUE
 isTRUE(all.equal(x, rep(x[1], length(x # ugly
[1] TRUE

Best,

Vincent
--
  Vincent Goulet, Associate Professor
  École d'actuariat
  Université Laval, Québec 
  [EMAIL PROTECTED]   http://vgoulet.act.ulaval.ca

__
R-help@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

__
R-help@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


Re: [R] Testing if all elements are equal in a vector/matrix

2005-08-29 Thread Francisco J. Zagmutt

Hi Doran

The documentation for isTRUE reads 'isTRUE(x)' is an abbreviation of 
'identical(TRUE,x)'  so actually Vincent's solutions is cleaner than using 
identical :)


Cheers

Francisco



From: Doran, Harold [EMAIL PROTECTED]
To: [EMAIL PROTECTED], r-help@stat.math.ethz.ch
Subject: Re: [R] Testing if all elements are equal in a vector/matrix
Date: Mon, 29 Aug 2005 15:49:20 -0400

See ?identical

-Original Message-
From: [EMAIL PROTECTED] 
[mailto:[EMAIL PROTECTED] On Behalf Of Vincent Goulet

Sent: Monday, August 29, 2005 3:35 PM
To: r-help@stat.math.ethz.ch
Subject: [R] Testing if all elements are equal in a vector/matrix


Is there a canonical way to check if all elements of a vector or matrix are 
the same? Solutions below work, but look hackish to me.


 x - rep(1, 10)
 all(x == x[1])  # == operator does not provide for small differences
[1] TRUE
 isTRUE(all.equal(x, rep(x[1], length(x # ugly
[1] TRUE

Best,

Vincent
--
  Vincent Goulet, Associate Professor
  École d'actuariat
  Université Laval, Québec
  [EMAIL PROTECTED]   http://vgoulet.act.ulaval.ca

__
R-help@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


__
R-help@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


__
R-help@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

Re: [R] Testing if all elements are equal in a vector/matrix

2005-08-29 Thread Patrick Burns
How about

diff(range(x))  tolerance

Patrick Burns
[EMAIL PROTECTED]
+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:

Is there a canonical way to check if all elements of a vector or matrix are 
the same? Solutions below work, but look hackish to me.

  

x - rep(1, 10)
all(x == x[1])  # == operator does not provide for small differences


[1] TRUE
  

isTRUE(all.equal(x, rep(x[1], length(x # ugly


[1] TRUE

Best,

Vincent
  


__
R-help@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


Re: [R] Testing if all elements are equal in a vector/matrix

2005-08-29 Thread Whit Armstrong
or perhaps

length(unique(x))==1



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Patrick Burns
Sent: Monday, August 29, 2005 5:22 PM
To: [EMAIL PROTECTED]
Cc: r-help@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
[EMAIL PROTECTED]
+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:

Is there a canonical way to check if all elements of a vector or matrix

are the same? Solutions below work, but look hackish to me.

  

x - rep(1, 10)
all(x == x[1])  # == operator does not provide for small differences


[1] TRUE
  

isTRUE(all.equal(x, rep(x[1], length(x # ugly


[1] TRUE

Best,

Vincent
  


__
R-help@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

__
R-help@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


Re: [R] Testing if all elements are equal in a vector/matrix

2005-08-29 Thread Vincent Goulet

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 :
 or perhaps

 length(unique(x))==1



 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of Patrick Burns
 Sent: Monday, August 29, 2005 5:22 PM
 To: [EMAIL PROTECTED]
 Cc: r-help@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
 [EMAIL PROTECTED]
 +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:
 Is there a canonical way to check if all elements of a vector or matrix
 
 are the same? Solutions below work, but look hackish to me.
 
 x - rep(1, 10)
 all(x == x[1])  # == operator does not provide for small differences
 
 [1] TRUE
 
 isTRUE(all.equal(x, rep(x[1], length(x # ugly
 
 [1] TRUE
 
 Best,
 
 Vincent

 __
 R-help@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

-- 
  Vincent Goulet, Professeur agrégé
  École d'actuariat
  Université Laval, Québec 
  [EMAIL PROTECTED]   http://vgoulet.act.ulaval.ca

__
R-help@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