Learn R Programming

SSBtools (version 1.7.0)

WildcardGlobbing: Row selection by wildcard/globbing

Description

The selected rows match combined requirements for all variables.

Usage

WildcardGlobbing(x, wg, sign = TRUE, invert = "!")

Value

Logical vector defining subset of rows.

Arguments

x

data.frame with character data

wg

data.frame with wildcard/globbing

sign

When FALSE, the result is inverted.

invert

Character to invert each single selection.

Author

Øyvind Langsrud

Details

This function is used by HierarchicalWildcardGlobbing and WildcardGlobbingVector and make use of grepl and glob2rx.

Examples

Run this code
# Create data input
data(precip)
data(mtcars)
x <- data.frame(car = rownames(mtcars)[rep(1:NROW(mtcars), each = 35)], city = names(precip), 
                stringsAsFactors = FALSE)

# Create globbing/wildcards input
wg <- data.frame(rbind(c("Merc*", "C*"), c("F*", "??????"), c("!?????????*", "!???????*")), 
                 stringsAsFactors = FALSE)
names(wg) <- names(x)

# Select the following combinations:
# - Cars starting with Merc and cities starting with C
# - Cars starting with F and six-letter cities 
# - Cars with less than nine letters and cities with less than seven letters
x[WildcardGlobbing(x, wg), ]

Run the code above in your browser using DataLab