Negate %like% in Data.Table Package | R

Viewed 2272

I am trying to use the %like% function from data.table pacakge but in reverse. I have not been able to find a way to negate the function. Any help will be much appreciate.

Would rather not use grepl with the invert = TRUE option. Trying to keep the code as simple as possible.

#Original code to find the match#

library(data.table)
Table1 <- data.table(Table1)
Table1 <-Table1[`Account Name` %like% 'Nike']
2 Answers

We can use

Table1[!`Account Name` %like% 'Nike']
#   Account Name      Col2
#1:       Others 0.4196231

data

set.seed(24)
Table1 <- data.table(`Account Name` = c("Nike brand", "Nike shoes",
       "Others"), Col2 = rnorm(3))

In case you wanted to create an actual "not like" function, you could do so as below

`%notlike%` <- Negate(`%like%`)

'something' %notlike% 'anotherthing'
# [1] TRUE
Related