[R] problem with all/all.equal

Peter Langfelder
Wed, 06 Apr 2011 22:32:06 -0000

On Wed, Apr 6, 2011 at 3:09 PM, Laura Smith <smithlaura937 at gmail.com>
wrote:
> Hi!
>
> In a function, I may have an instance in which all elements are equal.
>
>> x <- rep(1,5)
>>
>> x
> [1] 1 1 1 1 1
>> identical(x)
> Error in .Internal(identical(x, y, num.eq, single.NA, attrib.as.set)) :
> ?'y' is missing
>> all.equal(x)
> Error in is.expression(x) : 'x' is missing
>>

all looks at a logical vector (or two), and all.equal compares two
objects. For your purposes, you can ask whether

all (x==x[1])

for example.

Peter