Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

multiGSub

Analogs of grep(l) and (g)sub for multiple patterns and relacements


Description

These functions provide convenient pattern finding and substitution for multiple patterns.

Usage

multiGSub(patterns, replacements, x, ...)
multiSub(patterns, replacements, x, ...)
multiGrep(patterns, x, ..., sort = TRUE, value = FALSE, invert = FALSE)
multiGrepl(patterns, x, ...)

Arguments

patterns

A character vector of patterns.

replacements

A character vector of replacements; must be of the same length as patterns.

x

Character vector of strings in which the pattern finding and replacements should be carried out.

sort

Logical: should the output indices be sorted in increasing order?

value

Logical: should value rather than the index of the value be returned?

invert

Logical: should the search be inverted and only indices of elements of x matching none of the patterns be returned?

...

Other arguments to sub or grep

Details

For each element of x, patterns are sequentiall searched for and (for multiSub and multiGSub substituted with the corresponding replacement.

Value

multiSub and multiGSub return a character vector of the same length as x, with all patterns replaces by their replacements in each element of x. multiSub replaces each pattern in each element of x only once, multiGSub as many times as the pattern is found.

multiGrep returns the indices of those elements in x in which at least one of patterns was found, or, if invert is TRUE, the indices of elements in which none of the patterns were found. If value is TRUE, values rather than indices are returned.

multiGrepl returns a logical vector of the same length as x, with TRUE is any of the patterns matched the element of x, and FALSE otherwise.

Author(s)

Peter Langfelder

See Also

The workhorse functions sub, gsub, grep and grepl.


WGCNA

Weighted Correlation Network Analysis

v1.70-3
GPL (>= 2)
Authors
Peter Langfelder <Peter.Langfelder@gmail.com> and Steve Horvath <SHorvath@mednet.ucla.edu> with contributions by Chaochao Cai, Jun Dong, Jeremy Miller, Lin Song, Andy Yip, and Bin Zhang
Initial release
2021-02-17

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.