我试图grep一个字符串向量,其中一些包含问号.
我在做:
grep('\?',vectorofStrings)
并收到此错误:
Error: '\?' is an unrecognized escape in character string starting "\?"
如何确定'?'的正确转义过程?
Cha*_*ase 21
你也必须逃脱\:
vectorOfStrings <- c("Where is Waldo?", "I don't know", "This is ? random ?")
grep("\\?", vectorOfStrings)
#-----
[1] 1 3
Run Code Online (Sandbox Code Playgroud)
Tyl*_*ker 10
使用\\或fixed = TRUE参数,如:
vectorofStrings <-c("hello.", "where are you?", "?")
grep('\\?',vectorofStrings)
grep('?',vectorofStrings, fixed=TRUE)
Run Code Online (Sandbox Code Playgroud)