[R] vectors with equal values
arun
smartpink111 at yahoo.com
Thu Apr 18 16:38:29 CEST 2013
Hi,
Isn't that answered already?
vec2<-c(2,2,2,2,2,2,2)
if(length(unique(vec2))==1) "xxxxxxxxx" else "yyyyyyyyyyy"
#[1] "xxxxxxxxx"
vec2<-c(22,22,22,22,23,22,22)
if(length(unique(vec2))==1) "xxxxxxxxx" else "yyyyyyyyyyy"
#[1] "yyyyyyyyyyy"
vec2<-c(22,22,22,22,22,22,22)
if(length(unique(vec2))==1) "xxxxxxxxx" else "yyyyyyyyyyy"
[1] "xxxxxxxxx"
A.K.
>But if the vector is c(2,2,2,2,2,2,2) or (22,22,22,22,22)? And if I don't know the number that is equal?
>I want...if the vector has all values equal (but probably I don't know which number is...
>
>Thank you very much
----- Original Message -----
From: arun <smartpink111 at yahoo.com>
To: R help <r-help at r-project.org>
Cc:
Sent: Thursday, April 18, 2013 10:08 AM
Subject: Re: vectors with equal values
Hi,
Try:
vec1<-c(1,1,1,1,1,1,1,1,1)
if(all(vec1==1)) "xxxxxxxxx" else "yyyyyyyyyyy"
#[1] "xxxxxxxxx"
vec2<-c(rep(1,4),2)
if(all(vec2==1)) "xxxxxxxxx" else "yyyyyyyyyyy"
#[1] "yyyyyyyyyyy"
#or
if(length(unique(vec1))==1) "xxxxxxxxx" else "yyyyyyyyyyy"
#[1] "xxxxxxxxx"
if(length(unique(vec2))==1) "xxxxxxxxx" else "yyyyyyyyyyy"
#[1] "yyyyyyyyyyy"
A.K.
>Hi.
>
>I need some help. I have a vector like c(1,1,1,1,1,1,1,1,1), for example. I wanto to do in R some like this:
>
>if (all values equals) {
>"xxxxxxxxxxxxxxxxxx"
>} else {
>"yyyyyyyyyy"
>}
>
>How can I write the condition "all values equal" in R?
>
>Thank you
More information about the R-help
mailing list