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

From: Vincent Goulet <vincent.goulet_at_act.ulaval.ca>
Date: Tue 30 Aug 2005 - 05:35:21 EST

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 
  Vincent.Goulet_at_act.ulaval.ca   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
Received on Tue Aug 30 05:47:00 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:58 EST