biohazard
biohazard

Reputation: 2047

R: cannot grep() on "+" character?

Here is my data:

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

In hopes of separating the "+" from the "-", I tried running the following commands.

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

I can't figure out why the same grepl() command would work on "-" but not on "+".

Upvotes: 1

Views: 148

Answers (1)

Sven Hohenstein
Sven Hohenstein

Reputation: 81693

Use

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

or

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

or

"+" == rep$strand

Upvotes: 6

Related Questions