Home > Blockchain >  How do I deny the condition that is in if below
How do I deny the condition that is in if below

Time:12-24

How do I deny the condition that is in if below?

if(any(PV$DTT == DTest & PV$Week== Wk, na.rm = TRUE)){
....
}

In the condition above I am considering if it has PV$DTT == DTest & PV$Week== Wk. But if you want to deny it, for example, if you don't have PV$DTT == DTest & PV$Week== Wk, what would it look like?

CodePudding user response:

Depends on whether you want the entire condition to be TRUE or FALSE. You probably want !any. Make a small example:

a <- c(1, 1, 2, 2)
b <- c(3, 4, 3, 4)

cbind(a, b)
#      a b
# [1,] 1 3
# [2,] 1 4
# [3,] 2 3
# [4,] 2 4

a == 1 & b == 3
# [1]  TRUE FALSE FALSE FALSE
any(a == 1 & b == 3)
# [1] TRUE
!any(a == 1 & b == 3)
# [1] FALSE

a == 3 & b == 5
# [1] FALSE FALSE FALSE FALSE
any(a == 1 & b == 5)
# [1] FALSE
!any(a == 1 & b == 5)
# [1] TRUE

CodePudding user response:

In javascript you can deny with ! symbol

if(!(2 > 1)) {...}

I don't know if it is possible to do it in R as the same way

  •  Tags:  
  • r
  • Related