R:对"+"字符不能grep()吗?

bio*_*ard 1 regex r grepl

这是我的数据:

> rep$strand
  [1] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  [58] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + +
  [115] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  [172] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  [229] + + + + + + + + + + + + + + + + + + + +
Run Code Online (Sandbox Code Playgroud)

在分离的希望"+""-",我试图运行下面的命令.

grepl("-",rep$strand) #this gives me a list of TRUE/FALSE that seems correct
grepl("+",rep$strand) #this is all TRUE for some mysterious reason
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚为什么同一个grepl()命令可以工作"-"但不能工作"+".

Sve*_*ein 6

使用

grepl("\\+", rep$strand)
Run Code Online (Sandbox Code Playgroud)

要么

grepl("+", rep$strand, fixed = TRUE)
Run Code Online (Sandbox Code Playgroud)

要么

"+" == rep$strand
Run Code Online (Sandbox Code Playgroud)