# any

##### Are Some Values True?

Given a set of logical vectors, is at least one of the values true?

- Keywords
- logic

##### Usage

`any(…, na.rm = FALSE)`

##### Arguments

- …
zero or more logical vectors. Other objects of zero length are ignored, and the rest are coerced to logical ignoring any class.

- na.rm
logical. If true

`NA`

values are removed before the result is computed.

##### Details

This is a generic function: methods can be defined for it
directly or via the `Summary`

group generic.
For this to work properly, the arguments `…`

should be
unnamed, and dispatch is on the first argument.

Coercion of types other than integer (raw, double, complex, character, list) gives a warning as this is often unintentional.

This is a primitive function.

##### Value

The value is a logical vector of length one.

Let `x`

denote the concatenation of all the logical vectors in
`...`

(after coercion), after removing `NA`

s if requested by
`na.rm = TRUE`

.

The value returned is `TRUE`

if at least one of the values in
`x`

is `TRUE`

, and `FALSE`

if all of the values in
`x`

are `FALSE`

(including if there are no values). Otherwise
the value is `NA`

(which can only occur if `na.rm = FALSE`

and `…`

contains no `TRUE`

values and at least one
`NA`

value).

##### S4 methods

This is part of the S4 `Summary`

group generic. Methods for it must use the signature
`x, …, na.rm`

.

##### References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
*The New S Language*.
Wadsworth & Brooks/Cole.

##### See Also

`all`

, the ‘complement’ of `any`

.

##### Examples

`library(base)`

```
# NOT RUN {
range(x <- sort(round(stats::rnorm(10) - 1.2, 1)))
if(any(x < 0)) cat("x contains negative values\n")
# }
```

*Documentation reproduced from package base, version 3.4.3, License: Part of R 3.4.3*

### Community examples

**richie@datacamp.com**at Jan 18, 2017 base v3.3.2

Pass a vector to `any()`, and it will return `TRUE` if any of the elements are `TRUE`. ```{r} any(-2:2 < 0) any(1:5 < 0) ``` Pass several numbers to `any()`, and it will return `TRUE` if any of the arguments are `TRUE`. ```{r} any(FALSE, 99 > 66, 64 %% 8 == 1) any(FALSE, 99 < 66, 64 %% 8 == 1) ``` In fact, you can pass vectors into several arguments, and everything gets combined together before checking if any of the values are `TRUE`. ```{r} any( 1:5 < 0, rep.int(FALSE, 5), 99 > 66, seq.int(8, 64, 8) %% 8 == 1 ) ``` If there are any missing values, then `any()` returns `NA`. ```{r} any(-2:2 > 0, NA) ``` You can exclude missing values by setting `na.rm = TRUE`. ```{r} any(-2:2 > 0, NA, na.rm = TRUE) ```