r - 在 dplyr() 中使用 str_detect 跨两列进行匹配
问题描述
我正在尝试跨两列进行匹配mydata
以创建一个名为match
. 我首先要删除在Word1
or中包含“none”的所有行Word2
:
Token Word1 Word2
1 cat cat
2 dog cat
3 hamster none
4 sheep sheep
5 none hamster
我在中使用了以下代码dplyr()
:
mydata %>% filter(Word1 != "none" | Word2 != "none") %>%
mutate(match = str_detect(Word1 , Word2)) %>%
filter(match == FALSE)
我收到以下错误:
Error in mutate_impl(.data, dots) :
Evaluation error: Incorrectly nested parentheses in regexp pattern.
(U_REGEX_MISMATCHED_PAREN).
当我mydata %>% filter(Word1 != "none" | Word2 != "none")
只运行该函数时,它工作正常,所以我看不到括号中的错误。但也许我在这里遗漏了一些非常明显的东西!(我之前已经str_detect
成功使用过很多次了!)
我也找到了这个关于使用的答案fixed(x)
,但是当我将它应用到我的代码中时,mutate(match = str_detect(Word1 , Word2), fixed(x))
我在输出中得到了同样的错误。
解决方案
推荐阅读
- javascript - 输入后在搜索栏中保留文本
- scala - Spark SQL仅映射一列DataFrame
- android - 类型转换器不工作
- google-sheets - 无法在 Google 表格中使用 MINUS 函数解析公式
- c++ - TCP 服务器不等待客户端响应,如何解决这个问题?
- javascript - Javascript忽略上/下键上的某些列表项
- r - Linux Centos 7 上的 dplyr 0.7.5,选择功能不起作用
- openstreetmap - 如何找到有天桥的新节点?
- ionic3 - 离子浏览器版本
- javascript - MenuButton 不会打开菜单