[R] Compare three or more values?
Erik Iverson
eriki at ccbr.umn.edu
Wed Mar 23 19:47:31 CET 2011
Holly,
try
> length(unique(x)) == 1
where x is your vector of interest. But think about
how you want NA values to be treated, and also think about
R FAQ 7.31 if dealing with floating point numbers.
--Erik
Beale, Holly (NIH/NHGRI) [F] wrote:
> Is there a less cryptic way to compare three or more values?
>
> allTheSame<-c("red","red","red","red")
> notAllTheSame<-c(132,132,132,999)
>
> all.identical <- function(vectorToTest){
> cIdentical=sum(vectorToTest %in% vectorToTest[1])
> return(cIdentical==length(vectorToTest))
> }
>
> all.identical(allTheSame)
> all.identical(notAllTheSame)
>
> Thanks in advance,
> Holly
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list