我想要做的是在字符列表中搜索特定模式并返回位置,以便稍后我可以将它们排除。
我的数据是一个文本,其中每个单词都附有一个词性标记,格式为:
test
$text
[1] "This/DT is/VBZ a/DT short/JJ sentence/NN ,/, to/TO test/VB if/IN everything/NN is/VBZ working/VBG ./."
$POStags
[1] "DT" "VBZ" "DT" "JJ" "NN" "$," "TO" "VB" "IN" "NN" "VBZ"
[12] "VBG" "$."
我想过滤所有出现的“$”。和“$”。我尝试过以下方法:
grep("$.", test$POStags, value = TRUE)
返回character(0)
我是R的新手并且觉得应该有一个简单的解决方案,但不知怎的,我无法让它工作......提前感谢任何帮助!
grep("\\$(\\.|,)", test$POStags)
[1] 6 13
这个怎么样
which(grepl("$.",test$POStags,fixed = T) | grepl("$,",test$POStags,fixed = T))