【发布时间】:2014-02-09 20:37:49
【问题描述】:
这是我的数据:
> 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() 命令可以在"-" 上运行,但在"+" 上却不行。
【问题讨论】:
-
+是一个正则表达式元字符。您需要将其转义以删除其“元性”。 -
...用反斜杠完成。其中两个。
-
或 grepl("+", "some + in here", fixed=TRUE)
-
您可以在文档中找到有关正则表达式的更多详细信息:stat.ethz.ch/R-manual/R-devel/library/base/html/regex.html