R language grep function usage

   通常被用来进行数值计算比较多,字符串处理相对较少,而且关于字符串的函数也不多,用得多的就是substr、strsplit、paste、regexpr这几个了。实际上R关于字符串处理的功能是非常强大的,因为它甚至可以直接使用Perl的正则表达式,这也是R的一个理念,作为语言就把向量计算做到极致,作为环境,就在各领域都集成最好的。R中有grep系列的函数,可以用最强大的方式处理字符串的所有问题。

grep stands for global search regular expression and print out the line, Unix is a powerful text search tools, through regular expression search text, and print out the matching rows, including grep, egrep and fgrep (egrep is extended grep, fgrep is a fast way of searching did not really make use of regular expressions). Version of Linux using the GNU grep, the set of specifications also widely used, R is a function of the grep one.
  The core grep is a regular expression (Regular Expressions, often abbreviated as regex), the so-called regular expressions to match a pattern is to use a formula for a class of strings, many text editors or programming languages support this approach to character string operation, is introduced above the beginning of Unix tools like grep popular, widely used later. Especially in the language Perl regular expressions to an extreme.

  R语言中的grep函数可以在给定的字符串向量中搜索某个子字符串。grep函数可以像数据库查询一样对向量中的具有特定条件的元素进行查询。

The syntax is as follows:

grep(pattern, x, ignore.case = FALSE, perl = FALSE, value = FALSE, fixed = FALSE, useBytes = FALSE, invert = FALSE)

The meaning of each parameter is as follows:

(1) pattern: string type, regular expressions, specified search pattern, when the fixed parameter set to TRUE, may be a character string to be searched.

(2) x: vector of strings, a string to be searched.

(3) ignore.case: whether to ignore the case. It is FALSE, case sensitive, time is TRUE, ignoring case.

(4) perl: specifies whether the Perl Compatible Regular Expressions

(5) value: logical value is FALSE, grep search results returned position information is TRUE, the return value of the resulting position.

(6) fixed: logical value is TRUE, according to the pattern specified as a search string, and ignores the parameter settings conflict.

(7) useBytes: logic value, if true, is byte-match, rather than by matching characters.

(8) invert: logic value, the index value of the item, or, if TRUE, the match is not returned.

Published 10 original articles · won praise 0 · Views 319

Guess you like

Origin blog.csdn.net/weixin_44612629/article/details/103894248