R语言 “不像”运算符

vsdwdz23  于 2023-06-19  发布在  其他
关注(0)|答案(3)|浏览(129)

是否有可能在dplyr中使用过滤并使用类似运算符的负数?类似的东西(不起作用):

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

toe950271#

添加!是个不错的选择。如果你想要一个不同的方向,你可以创建你自己的函数,我做了一个类似于%in%的函数:

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

在你的例子中,创建一个这样的函数:

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

vsikbqxv2#

就像这样:

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

因为这样放置感叹号使得语句not

c3frrgcw

c3frrgcw3#

Tidyverse style:

library(tidyverse)
my_df %>% filter(!str_detect(text,'dirty talk')

相关问题