Learn R Programming

textshape (version 1.7.5)

grab_match: Get Elements Matching Between 2 Points

Description

Use regexes to get all the elements between two points.

Usage

grab_match(x, from = NULL, to = NULL, from.n = 1, to.n = 1, ...)

# S3 method for character grab_match(x, from = NULL, to = NULL, from.n = 1, to.n = 1, ...)

# S3 method for list grab_match(x, from = NULL, to = NULL, from.n = 1, to.n = 1, ...)

# S3 method for data.frame grab_match( x, from = NULL, to = NULL, from.n = 1, to.n = 1, text.var = TRUE, ... )

Value

Returns a subset of the original data set.

Arguments

x

A character vector, data.frame, or list.

from

A regex to start getting from (if NULL defaults to the first element/row).

to

A regex to get up to (if NULL defaults to the last element/row).

from.n

If more than one element matches from this dictates which one should be used. Must be an integer up to the number of possible matches, 'first' (equal to 1), 'last' (the last match possible), or 'n' (the same as 'last').

to.n

If more than one element matches to this dictates which one should be used. Must be an integer up to the number of possible matches, 'first' (equal to 1), 'last' (the last match possible), or 'n' (the same as 'last').

text.var

The name of the text variable with matches. If TRUE grab_match tries to detect the text column.

...

Other arguments passed to grep, most notable is ignore.case.

Examples

Run this code
grab_match(DATA$state, from = 'dumb', to = 'liar')
grab_match(DATA$state, from = 'dumb')
grab_match(DATA$state, to = 'liar')
grab_match(DATA$state, from = 'no', to = 'the', ignore.case = TRUE)
grab_match(DATA$state, from = 'no', to = 'the', ignore.case = TRUE, 
    from.n = 'first', to.n = 'last')
grab_match(as.list(DATA$state), from = 'dumb', to = 'liar')

## Data.frame: attempts to find text.var
grab_match(DATA, from = 'dumb', to = 'liar')

Run the code above in your browser using DataLab