WildcardGlobbing: Row selection by wildcard/globbing

Description Usage Arguments Details Value Author(s) Examples

View source: R/PatternMatching.R

Description

The selected rows match combined requirements for all variables.

Usage

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

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.

Details

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

Value

Logical vector defining subset of rows.

Author(s)

Øyvind Langsrud

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# 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), ]

statisticsnorway/SSBtools documentation built on March 3, 2020, 1:34 a.m.