grepl.sub: Subset a data frame if a specified pattern is found in a...

Description Usage Arguments Examples

View source: R/utils.R

Description

Subset a data frame if a specified pattern is found in a character string

Usage

1
grepl.sub(data, pattern, Var, keep.found = TRUE, ...)

Arguments

data

data frame.

pattern

character vector containing a regular expression to be matched in the given character vector.

Var

character vector of the variables that the pattern should be found in.

keep.found

logical. whether or not to keep observations where the pattern is found (TRUE) or not found (FALSE).

...

arguments to pass to grepl.

Examples

1
2
3
4
5
6
7
# Create data frame
ABData <- data.frame(a = c("London, UK", "Oxford, UK", "Berlin, DE",
                    "Hamburg, DE", "Oslo, NO"),
                    b = c(8, 0.1, 3, 2, 1))

# Keep only data from Germany (DE)
ABGermany <- grepl.sub(data = ABData, pattern = "DE", Var = "a")

DataCombine documentation built on May 30, 2017, 2:52 a.m.