【发布时间】:2020-06-30 05:10:53
【问题描述】:
这是关于R的。有人可以看看这个:
{library(forcats)
x <- filter(gss_cat, rincome != regex("not applicable", ignore_case = TRUE))}
ignore_case = TRUE 无效。 “不适用”和“不适用”在搜索中看起来仍然不同。
【问题讨论】:
标签: r regex ignore-case
这是关于R的。有人可以看看这个:
{library(forcats)
x <- filter(gss_cat, rincome != regex("not applicable", ignore_case = TRUE))}
ignore_case = TRUE 无效。 “不适用”和“不适用”在搜索中看起来仍然不同。
【问题讨论】:
标签: r regex ignore-case
考虑这个例子:
df <- data.frame(a = c('This is not applicable', 'But this is applicable',
'This is still NOT aPPLicable'))
您需要在stringr 函数之一中使用regex,例如str_detect:
library(dplyr)
library(stringr)
df %>% filter(str_detect(a, regex('not applicable',
ignore_case = TRUE), negate = TRUE))
# a
#1 But this is applicable
或者在基础 R 中使用 subset 和 grepl
subset(df, !grepl('not applicable', a, ignore.case = TRUE))
【讨论】: