have fun
have fun

Reputation: 381

Is there a built-in function "none"?

I hope the question is not too foolish.

Is there a built-in R function that returns TRUE when all the cases are FALSE?

Similar to any() or all() but when, in the case of a logical vector of 2, TRUE TRUE returns FALSE, TRUE FALSE returns FALSE and FALSE FALSE returns TRUE.

I would call it none().

Upvotes: 4

Views: 2126

Answers (3)

Stéphane Laurent
Stéphane Laurent

Reputation: 84689

Negate(any) ?

> none <- Negate(any)
> none(c(TRUE,TRUE))
[1] FALSE
> none(c(TRUE,FALSE))
[1] FALSE
> none(c(FALSE,FALSE))
[1] TRUE

Upvotes: 3

989
989

Reputation: 12935

Or all:

all(!vec)

Or using sum:

sum(vec)==0

where vec is your vector.

Upvotes: 1

akrun
akrun

Reputation: 887851

We can use ! with any

!any(c(FALSE, FALSE))

Upvotes: 8

Related Questions