Learn R Programming

Epi (version 2.56)

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, ... )

Value

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

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.

Author

Bendix Carstensen, b@bxc.dk, http://bendixcarstensen.com

See Also

Examples

Run this code
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 )

Run the code above in your browser using DataLab