all() and any()
get_help() docs
The all() and any() functions come with R and are part of the Base R {base} package.
We use these functions to ask if all values in a given array meet some logical condition (all()), or if any values in a given array meet some logical condition (any()). In other words…
all() asks: “Is this thing TRUE for all of the array values?”any() asks: “Is this thing TRUE for any (at least one) of the array values?”all(logical statement about an array)
any(logical statement about an array)# Is it TRUE that ALL of the values in this array are greater than 5?
my_array <- c(6, 77, 8, 22)
all(my_array > 5)## [1] TRUE
# Is it TRUE that ANY of the values in this array are greater than 5?
my_array <- c(4, 5, 7, 8, 22)
any(my_array > 5)## [1] TRUE
# Is it TRUE that ALL of the strings in this array have 3 characters?
my_array <- c("one", "two", "three")
all( nchar(my_array) == 3 )## [1] FALSE
# Is it TRUE that ANY of the strings in this array have 3 characters?
my_array <- c("one", "two", "three")
any( nchar(my_array) == 3 )## [1] TRUE