Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape a question mark in R?

Tags:

regex

r

I am trying to grep a vector of strings and some of them contain question marks.

I am doing:

grep('\?',vectorofStrings) and getting this error:

Error: '\?' is an unrecognized escape in character string starting "\?"

How can I determine the proper escaping procedure for '?'

like image 658
pedrosaurio Avatar asked May 15 '12 14:05

pedrosaurio


People also ask

How do I remove a question mark from data in R?

If we want to create the correlation matrix without question marks then we can use the na. label argument and set it to blank as shown in the below Example.

How do you escape a question mark?

Use a backslash character \ to escape the question mark.


1 Answers

You have to escape \ as well:

vectorOfStrings <- c("Where is Waldo?", "I don't know", "This is ? random ?")
grep("\\?", vectorOfStrings)
#-----
[1] 1 3
like image 134
Chase Avatar answered Sep 20 '22 12:09

Chase