dfrm$dc <- c("dog", "cat", "rabbit")[ findInterval(dfrm$b, c(1, 2.5, 5.5, Inf)) ]
The findInterval approach will be much faster than the nested ifelse strategies, and I assume this is much faster than the function that iterates over unnecessary if . Those of us who work with big data notice the differences when we choose inefficient algorithms.
This did not actually address the request, but I do not always think that new R users will know the most expressive or effective approach to problems. The request to βuse IFβ sounded like an attempt to translate coding approaches specific to the two main macro-statistical processors SPSS and SAS. The R if control structure is usually not an effective approach to recoding a column, since an argument to its first position will be evaluated only for the first element. By itself, it does not process the column, while the ifelse function does this. The cut function could be used here (with the appropriate breaks and labels parameters), although it would put a factor value instead of a character value. The findInterval approach was chosen for its ability to return multiple levels (which cannot be one ifelse ). I think ifelse chaining or nesting gets quickly ugly and confusing after about two or three levels of nesting.
source share