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

lgrep

Convenience versions of grep


Description

Often you want the elements of a vector (or its names or levels) that meet a certain pattern. But grep only gives you the position, so these functions are designed to give you that.

Usage

fgrep( pattern, x, ... )
ngrep( pattern, x, ... )
lgrep( pattern, x, ... )

Arguments

pattern

Pattern searched for.

x

Object where pattern is searched. Or in whose names or levels attributes pattern is sought.

...

Arguments passed on to grep.

Value

Elements of the input x (fgrep) or its names attribute (ngrep) or levels attribute (lgrep).

Author(s)

See Also

Examples

ff <- factor( ll <- paste( sample( letters[1:3], 20, replace=TRUE ),
                           sample( letters[1:3], 20, replace=TRUE ), sep="" ) )
ff
fgrep( "a", ff )
fgrep( "a", ll )
ngrep( "a", ff )
lgrep( "a", ff )
lgrep( "a", ff, invert=TRUE )

Epi

Statistical Analysis in Epidemiology

v2.44
GPL-2
Authors
Bendix Carstensen [aut, cre], Martyn Plummer [aut], Esa Laara [ctb], Michael Hills [ctb]
Initial release
2021-02-28

We don't support your browser anymore

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