“not like” 运算符

huangapple go评论76阅读模式
英文:

"not like" operator

问题

dplyr中是否有可能使用筛选并使用负面的like运算符?类似于(不起作用的):

my_df %>%
  filter(text !%like% "dirty talk")
英文:

Is there a possibility to use filtering in dplyr and use negative of like operator? Something like (which does not work):

my_df %>% 
  filter(text !%like% "dirty talk")

答案1

得分: 3

在条件开头添加感叹号是一个很好的选项。如果你想要不同的操作,你可以创建自己的函数,就像我所做的模仿%in%一样:

`%notin%` <- Negate('%in%')

所以在你的情况下,创建一个类似这样的函数:

`%notlike%` <- Negate('%like%')
英文:

Adding the ! at the start of the condition is a great option. If you want a different direction, you can create your own function, which I did as an analog to %in%:

`%notin%` &lt;- Negate(&#39;%in%&#39;) 

So in your case, create a function like this:

`%notlike%` &lt;- Negate(&#39;%like%&#39;)

答案2

得分: 1

就像这样:

my_df %>%
    filter(!text %like% "dirty talk")

由于将感叹号放置在这样的位置使语句成为“not”。

英文:

just like this:

my_df %&gt;% 
    filter(!text %like% &quot;dirty talk&quot;)

Since placing the exclamation like so makes the statement not

答案3

得分: 0

库(tidyverse)
my_df %>% filter(!str_detect(text,'脏话'))

英文:

tidyverse style:

library(tidyverse)
my_df %&gt;% filter(!str_detect(text,&#39;dirty talk&#39;)

huangapple
  • 本文由 发表于 2023年6月15日 21:17:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76482907.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定