[R] Testing if all elements are equal in a vector/matrix
Vincent Goulet
vincent.goulet at act.ulaval.ca
Mon Aug 29 21:35:21 CEST 2005
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
More information about the R-help
mailing list