Complete word matching using grepl in R

前端 未结 3 1668

Consider the following example:

> testLines <- c(\"I don\'t want to match this\",\"This is what I want to match\")
> grepl(\'is\',testLines)
> [         


        
3条回答
  •  迷失自我
    2020-11-29 08:57

    "\<" is another escape sequence for the beginning of a word, and "\>" is the end. In R strings you need to double the backslashes, so:

    > grepl("\\", c("this", "who is it?", "is it?", "it is!", "iso"))
    [1] FALSE  TRUE  TRUE  TRUE FALSE
    

    Note that this matches "is!" but not "iso".

提交回复
热议问题