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 '?'
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.
Use a backslash character \ to escape the question mark.
You have to escape \
as well:
vectorOfStrings <- c("Where is Waldo?", "I don't know", "This is ? random ?")
grep("\\?", vectorOfStrings)
#-----
[1] 1 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With