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']
We can use
Table1[!`Account Name` %like% 'Nike']
# Account Name Col2
#1: Others 0.4196231
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With