mbers1<-c(4,5,9,11,17)
if(y %in% numbers1){
print("yes")}
else {print("no")}
}
fun3(8)
#[1] "no"
fun3(9)
#[1] "yes"
fun3(10)
#[1] "no"
fun3(11)
#[1] "yes"
A.K.
- Original Message -
From: Dominic Roye
To: r-help@r-projec
HI,
Try ifelse
fun1<-function(y){
ifelse(y==c(4,5,9,11,17),"yes","no")
}
> fun1(9)
#[1] "no" "no" "yes" "no" "no"
A.K.
- Original Message -
From: Dominic Roye
To: r-help@r-project.org
Cc:
Sent: Sunda
Take a look at ?ifelse
Cheers,
Michael
On Aug 12, 2012, at 3:12 AM, Dominic Roye wrote:
> Hello everybody,
>
> I don't understand what I'm doing wrong. But it isn't possible that each
> element of the if-condition is tested for each vector element?
>
> y <- c(1:20)
>> y
> [1] 1 2 3 4 5
Hello everybody,
I don't understand what I'm doing wrong. But it isn't possible that each
element of the if-condition is tested for each vector element?
y <- c(1:20)
> y
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
> if (y == c(4,5,9,11,17)) { print("yes") } else { print("no
4 matches
Mail list logo