gpt4 book ai didi

r - R 中的 stri_detect_regex 错误

转载 作者:行者123 更新时间:2023-12-03 23:57:09 24 4
gpt4 key购买 nike

我收到此错误

Error in stri_detect_regex(string, pattern, opts_regex = opts(pattern)) : Incorrectly nested parentheses in regexp 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))})

其中 named_RN$V1好像
aldosterone
renin
potassium
calcitrol

final_RN$named_RN好像
aldosterone, creatinine 
human, warfarin
aspirin, renin, calcitrol
magnesium, calcitrol

我的代码旨在在 named_RN 内创建一个新变量显示每个短语的原始计数,因此 named_RN好像
V1              search
aldosterone 1
renin 0
potassium 0
calcitrol 2

请指教。谢谢。

最佳答案

由于您使用的是固定字符串,而不是正则表达式,因此您需要告诉正则表达式引擎将模式用作纯文字文本。你可以这样使用它:

str_detect(final_RN$named_RN, fixed(x))
^^^^^^^^

"Fixed matches" :

fixed(x) only matches the exact sequence of bytes specified by x. This is a very limited “pattern”, but the restriction can make matching much faster.



您也可以考虑 coll(x)如果您想在执行不区分大小写的搜索时使用人类语言整理规则。

关于r - R 中的 stri_detect_regex 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45828985/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com