# all

##### Are All Values True?

Given a set of logical vectors, are all of the values true?

- Keywords
- logic

##### Usage

`all(…, 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 all of the values in `x`

are
`TRUE`

(including if there are no values), and `FALSE`

if at
least one of the values in `x`

is `FALSE`

. Otherwise the
value is `NA`

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

and
`…`

contains no `FALSE`

values and at least one
`NA`

value).

##### Note

That `all(logical(0))`

is true is a useful convention:
it ensures that

all(all(x), all(y)) == all(x, y)

even if `x`

has length zero.

##### 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

`any`

, the ‘complement’ of `all`

, and
`stopifnot(*)`

which is an `all(*)`

‘insurance’.

##### Examples

`library(base)`

```
# NOT RUN {
range(x <- sort(round(stats::rnorm(10) - 1.2, 1)))
if(all(x < 0)) cat("all x values are negative\n")
all(logical(0)) # true, as all zero of the elements are true.
# }
```

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

### Community examples

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

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