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

时间:2014-02-09 20:37:50

标签: regex r grepl

这是我的数据:

> rep$strand
  [1] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  [58] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + +
  [115] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  [172] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  [229] + + + + + + + + + + + + + + + + + + + +

为了将"+""-"分开,我尝试运行以下命令。

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

我无法弄清楚为什么相同的grepl()命令可用于"-",但不能用于"+"

1 个答案:

答案 0 :(得分:6)

使用

grepl("\\+", rep$strand)

grepl("+", rep$strand, fixed = TRUE)

"+" == rep$strand