One thing I want to do all the time in my R code is to test whether certain conditions hold for a vector, such as whether it contains any or all values equal to some specified value. The Rish way to do this is to create a boolean vector and use any or all, for example:
any(is.na(my_big_vector))
all(my_big_vector == my_big_vector[[1]])
...
It seems really inefficient to me to allocate a big vector and fill it with values just to throw it away (especially if any()
or all()
call can be short circuited after testing just a couple of the values. Is there a better way to do this or should I just hand in my desire to write code that is both efficient and succinct when working in R?