I have a vector of size 5 e.g.:
a<-c(1,4,6,3,2)
I also have another vector of size 1:
b<-9
I would like to write the following if condition:
if (a>b) { 1
}
else 0
}
I get the following warning:
Warning message:
In if (fitness_neighbours > user_fitness) { :
the condition has length > 1 and only the first element will be used
What I would actually like it to do is to check if any of the elements in ‘a’ satisfy the condition.
Use
any()and a comparison:Another way of doing it using
pmax():That’s saying that if any of the max of (
a,b) is equal to the value ina, thenamust be greater.