Any() is a predicate functional that takes a predicate function .f and an iterable object .x and:

  1. iterates over each item i in object .x,

  2. evaluates .f(i),

  3. and ultimately returns TRUE if any items i in object .x evaluate as TRUE.

Any(.x, .f, ..., na.rm = FALSE)

Arguments

.x

An iterable object.

.f

A predicate function.

...

Further arguments passed to the predicate function.

na.rm

A logical value indicating whether NA values should be stripped before the computation proceeds.

Value

A logical value indicating if any items evaluated as TRUE.

See also

All to test if all items in an object evaluate to TRUE.

Other predicate functionals: All; Reject

Examples

# Examples data(mtcars) Any(mtcars, is.numeric) # TRUE
#> [1] TRUE
Any(mtcars, is.character) # FALSE
#> [1] FALSE
mtcars$am <- factor(mtcars$am) Any(mtcars, is.numeric) # TRUE
#> [1] TRUE
Any(mtcars, is.factor) # TRUE
#> [1] TRUE
# Handles NAs and NULLs Any(list(NA, "3", NULL), is.numeric) # FALSE
#> [1] FALSE
Any(list(NA, 3, NULL), is.numeric) # TRUE
#> [1] TRUE
Any(list(NA, "3", NULL, 5), is.numeric) #TRUE
#> [1] TRUE
# Use na.rm = TRUE to remove NULLS Any(list(NA, FALSE), Identity) # NA
#> [1] NA
Any(list(NA, FALSE), Identity, na.rm = TRUE) # FALSE
#> [1] FALSE