if ... else and ifelse
Let’s make this a quick and quite basic one. There is this incredibly useful function in R called ifelse(). It’s basically a vectorized version of an if … else control structure every programming language has in one way or the other. ifelse() has, in my view, two major advantages over if … else:
It’s super fast. It’s more convenient to use. The basic idea is that you have a vector of values and whenever you want to test these values against some kind of condition, you want to have a specific value in another vector.