In discusion bellow this post, there is comment:
Don't use which.
With several upvotes.
Why is using which
in R bad and what are alternatives/preferable approaches?
In discusion bellow this post, there is comment:
Don't use which.
With several upvotes.
Why is using which
in R bad and what are alternatives/preferable approaches?
It should not be considered as a general recommendation, of course. It was just redundant in those conditions. I assume the problem was to catch the output of some function (or to use inside an if statement). If that's the case,
a <- which(1:3 == 5)
length(a) != 0
is the same as
b <- 1:3 == 5
any(b)
and the latter is clearly more elegant.