One thing that I want to do all the time in my R code is to check whether certain conditions for the vector are preserved, for example, whether it contains any or all values equal to some given value. RThe ish way to do this is to create a logical vector and use all or all, for example:
any(is.na(my_big_vector))
all(my_big_vector == my_big_vector[[1]])
...
It seems inefficient to allocate a large vector and fill it with values, just to throw it away (especially if the call any()or all()can be short-circuited after testing only a few values. Is there a better way to do this, or should I just hand over his desire to write code that is efficient and brief when working in R?
source
share