R语言:函数与正则

sub(pattern, replacement, x, ignore.case = FALSE, perl = FALSE,fixed = FALSE, useBytes = FALSE)。

 

gsub(pattern, replacement, x, ignore.case = FALSE, perl = FALSE,fixed = FALSE, useBytes = FALSE)。

 

sub函数替换首次出现的,gsub函数比之多了个g,全部替换,ignore.case=TRUE忽略大小写,fixed=TRUE精确匹配。

 

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

 

grepl(pattern, x, ignore.case = FALSE, perl = FALSE,fixed = FALSE, useBytes = FALSE)。

 

value=FALSE,grep函数返回整数索引,value=TRUE,grep函数返回值。fixed=TRUE,则是精确匹配,invert=TRUE,则是返回不匹配。grepl函数比grep函数多了个l,返回逻辑值。

 

grep函数用invert,grepl函数用!。

 

regexpr(pattern, text, ignore.case = FALSE, perl = FALSE,fixed = FALSE, useBytes = FALSE)。

 

gregexpr(pattern, text, ignore.case = FALSE, perl = FALSE,fixed = FALSE, useBytes = FALSE)。

 

regexec(pattern, text, ignore.case = FALSE, perl = FALSE,fixed = FALSE, useBytes = FALSE)。

 

regexpr,regular expression的简写,返回每元素首次匹配的开始位置构成的vector。regexec返回list。gregexpr函数比regexpr函数多了个g,返回每元素全部匹配的开始位置构成的list。

posted @ 2020-05-31 18:24  ForestYe  阅读(360)  评论(0)    收藏  举报