"%ni%" is a convenience shortcut for the negation of the match function (i.e. the %in%" operator).

x %ni% y

Arguments

x

the values to be negatively matched.

y

the values to be negatively matched against.

Value

A logical vector of the same length as x which is FALSE for matching values of y and TRUE for non-matching values of y.

See also

Author

Craig P. Hutton, Craig.Hutton@gov.bc.ca

Examples

c(1:100) %ni% c(2, 3, 5, 10, 78:91)
#>   [1]  TRUE FALSE FALSE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE
#>  [13]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
#>  [25]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
#>  [37]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
#>  [49]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
#>  [61]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
#>  [73]  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#>  [85] FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
#>  [97]  TRUE  TRUE  TRUE  TRUE

#subset data to extract rows with matching values using "%in%"
subset(pdata, g %in% c("a", "e"))
#> # A tibble: 4,944 × 10
#>       id d          g     high_low even     y1    y2    x1    x2    x3
#>    <int> <date>     <fct> <chr>    <lgl> <dbl> <dbl> <int> <int> <int>
#>  1     1 2008-01-01 e     high     FALSE 106.  118.     59   116   248
#>  2     5 2008-01-01 a     high     FALSE  99.7 113.     96   196   284
#>  3     6 2008-01-01 a     high     TRUE  102.  114.     19   163   206
#>  4     9 2008-01-01 e     low      FALSE  99.8  89.8    92   106   277
#>  5    11 2008-01-01 a     high     FALSE  93.8 102.     56   142   285
#>  6    12 2008-01-01 a     low      TRUE   96.5  92.4   100   111   277
#>  7    13 2008-01-01 a     low      FALSE  86.6  86.0    69   119   228
#>  8    14 2008-01-01 a     high     TRUE   86.5 105.     44   182   290
#>  9    15 2008-01-01 a     high     FALSE  99.6 101.     91   124   294
#> 10    19 2008-01-01 a     high     FALSE  99.6 108.      3   139   275
#> # … with 4,934 more rows

#subset data to extract rows with non-matching values using "%ni%"
subset(pdata, g %ni% c("a", "e"))
#> # A tibble: 7,056 × 10
#>       id d          g     high_low even     y1    y2    x1    x2    x3
#>    <int> <date>     <fct> <chr>    <lgl> <dbl> <dbl> <int> <int> <int>
#>  1     2 2008-01-01 c     high     TRUE   96.5 107.      5   101   238
#>  2     3 2008-01-01 d     low      FALSE  99.3  96.2    71   111   250
#>  3     4 2008-01-01 c     high     TRUE  109.  102.     60   130   287
#>  4     7 2008-01-01 d     low      FALSE  91.0  87.9    77   133   201
#>  5     8 2008-01-01 b     low      TRUE  109.   98.7    74   191   249
#>  6    10 2008-01-01 c     low      TRUE  122.   83.6     4   134   209
#>  7    16 2008-01-01 b     low      TRUE  112.   99.8    35   179   295
#>  8    17 2008-01-01 c     low      FALSE  91.1  88.1    27   111   218
#>  9    18 2008-01-01 b     low      TRUE  103.   86.2    27   187   210
#> 10    20 2008-01-01 c     low      TRUE  109.   82.7    71   146   267
#> # … with 7,046 more rows

#equivalent to subset function for tidyverse users
dplyr::filter(pdata, g %ni% c("a", "e"))
#> # A tibble: 7,056 × 10
#>       id d          g     high_low even     y1    y2    x1    x2    x3
#>    <int> <date>     <fct> <chr>    <lgl> <dbl> <dbl> <int> <int> <int>
#>  1     2 2008-01-01 c     high     TRUE   96.5 107.      5   101   238
#>  2     3 2008-01-01 d     low      FALSE  99.3  96.2    71   111   250
#>  3     4 2008-01-01 c     high     TRUE  109.  102.     60   130   287
#>  4     7 2008-01-01 d     low      FALSE  91.0  87.9    77   133   201
#>  5     8 2008-01-01 b     low      TRUE  109.   98.7    74   191   249
#>  6    10 2008-01-01 c     low      TRUE  122.   83.6     4   134   209
#>  7    16 2008-01-01 b     low      TRUE  112.   99.8    35   179   295
#>  8    17 2008-01-01 c     low      FALSE  91.1  88.1    27   111   218
#>  9    18 2008-01-01 b     low      TRUE  103.   86.2    27   187   210
#> 10    20 2008-01-01 c     low      TRUE  109.   82.7    71   146   267
#> # … with 7,046 more rows