在R中的数据帧中用正则表达式检测字边界 [英] detecting word boundary with regex in data frame in R
本文介绍了在R中的数据帧中用正则表达式检测字边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为的数据框,全部
有一列因素,这些因素包括word
,nonword
等等。我的目标是只选择具有因子值word的行。
I have a data.frame named all
that has a column of factors, these factors include "word"
,"nonword"
and some others. My goal is to select only the rows that have the factor value "word".
我的解决方案 grep(\bword\b,all [,5])
如何不能识别字边界?
推荐答案
,您需要两次 \
:
grep("\\bword\\b", all[5])
替代解决方案:
grep("^word$", all[5])
which(all[5] == "word")
这篇关于在R中的数据帧中用正则表达式检测字边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文