negating using values !

when would you do this:

  1. !(dataframe$columnA == 222 & dataframe$columnB == 1234)

vs.

  1. (dataframe$columnA != 222 & dataframe$columnB !=1234)
dataframe <- data.frame(columnA=c(222,222,111,111), columnB=c(1234,9999,1234,9999))

dataframe
#>   columnA columnB
#> 1     222    1234
#> 2     222    9999
#> 3     111    1234
#> 4     111    9999

# this one gives all rows that are not row 1
!(dataframe$columnA == 222 & dataframe$columnB == 1234)
#> [1] FALSE  TRUE  TRUE  TRUE

# this one gives the intersection of rows 3-4 and rows 2,4
(dataframe$columnA != 222 & dataframe$columnB !=1234)
#> [1] FALSE FALSE FALSE  TRUE

Created on 2019-06-11 by the reprex package (v0.3.0)

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.