all() and any()
   get_help() docs


Description

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…

Conceptual Usage

all(logical statement about an array)

any(logical statement about an array)

Examples


# 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