From: "Doran, Harold" <HDoran at air.org>
To: <vincent.goulet at act.ulaval.ca>, <r-help at 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: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Vincent Goulet
Sent: Monday, August 29, 2005 3:35 PM
To: r-help at 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
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