Skip to content
Back to formatted view

Raw Message

Message-ID: <70222FFE-1153-4B1D-ADB3-3E335C02A3BF@soc.soton.ac.uk>
Date: 2005-08-30T10:16:20Z
From: robin hankin
Subject: Testing if all elements are equal in a vector/matrix
In-Reply-To: <200508291535.21230.vincent.goulet@act.ulaval.ca>

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
>   Vincent.Goulet at act.ulaval.ca   http://vgoulet.act.ulaval.ca
>
> ______________________________________________
> 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
>

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