swe*_*ity 5 regex error-handling text r dataframe
我收到此错误
stri_detect_regex(string, pattern, opts_regex = opts(pattern)) 中的错误:正则表达式模式中的括号嵌套不正确。(U_REGEX_MISMATCHED_PAREN)
当我运行代码时
# find occurrences of initial dataframe
named_RN$search <- map_int(named_RN$V1, function(x){sum(str_detect(final_RN$named_RN, pattern = x))})
Run Code Online (Sandbox Code Playgroud)
其中named_RN$V1看起来像
aldosterone
renin
potassium
calcitrol
Run Code Online (Sandbox Code Playgroud)
看起来final_RN$named_RN像
aldosterone, creatinine
human, warfarin
aspirin, renin, calcitrol
magnesium, calcitrol
Run Code Online (Sandbox Code Playgroud)
我的代码旨在创建一个新变量,其中named_RN显示每个短语的原始计数,因此named_RN看起来像
V1 search
aldosterone 1
renin 0
potassium 0
calcitrol 2
Run Code Online (Sandbox Code Playgroud)
请指教。谢谢。
由于您使用的是固定字符串,而不是正则表达式,因此您需要告诉正则表达式引擎将模式用作纯文本。你可以这样使用它:
\n\nstr_detect(final_RN$named_RN, fixed(x))\n ^^^^^^^^\nRun Code Online (Sandbox Code Playgroud)\n\n请参阅“固定匹配”:
\n\n\n\n\n\n
fixed(x)仅匹配指定的确切字节序列x。这是一个非常有限的 \xe2\x80\x9cpattern\xe2\x80\x9d,但这种限制可以使匹配速度更快。
您也可以考虑coll(x)在执行不区分大小写的搜索时是否想要使用人类语言排序规则。