在R中的另一个字符串中查找字符串

use*_*657 2 string compare r

我想在R中的另一个字符串中找到一个字符串.字符串如下.我希望能够将字符串a与字符串b匹配,并且输出应该是a == b返回TRUE

a <- "6250;7250;6251"
b <- "7250"
a == b                 #FALSE
Run Code Online (Sandbox Code Playgroud)

A5C*_*2T1 10

你可以使用regmatchesgregexpr,但你的问题目前有些模糊,所以我不肯定这是你正在寻找的:

> regmatches(a, gregexpr(b, a))
[[1]]
[1] "7250"

> regmatches(a, gregexpr(b, a), invert=TRUE)
[[1]]
[1] "6250;" ";6251"
Run Code Online (Sandbox Code Playgroud)

根据您更新的问题,您可能正在寻找grepl.

> grepl(b, a)
[1] TRUE
> grepl(999, a)
[1] FALSE
Run Code Online (Sandbox Code Playgroud)

^^我们基本上是说"在'a'中寻找'b'".