I need a function that checks if all the coordinates of the vector are equal.
a = rep(1, 5)
Let the previous output be TRUE.
b = c(rep(1, 4),2)
Let the previous output be FALSE.
I need a function that checks if all the coordinates of the vector are equal.
a = rep(1, 5)
Let the previous output be TRUE.
b = c(rep(1, 4),2)
Let the previous output be FALSE.
I understood,
all(a[1] == a)
and
all(b[1] == b)
Complementing Wagner's response. It is correct, but it does not work if the vectors contain NA
values.
> a = rep(NA, 5)
> all(a[1] == a)
[1] NA
> b = c(rep(1, 4),NA)
> all(b[1] == b)
[1] NA
In this case you could use the following comparisons:
> isTRUE(all.equal(rep(a[1], length(a)), a))
[1] TRUE
> isTRUE(all.equal(rep(b[1], length(b)), b))
[1] FALSE