in_detect: Matching Values and Intervals

Description Usage Arguments Details Value See Also Examples

Description

Operators for detecting which values are within a given interval or set.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
x %in{}% table

x %out{}% table

x %in[]% interval

x %out[]% interval

x %in()% interval

x %out()% interval

x %in(]% interval

x %out(]% interval

x %in[)% interval

x %out[)% interval

x %in~% pattern

x %out~% pattern

x %in~p% pattern

x %out~p% pattern

x %in~f% pattern

x %out~f% pattern

x %in#% count

x %out#% count

Arguments

x

vector or array of values to be matched.

table

vector or list to be matched against.

interval

numeric vector defining a range to be matched against.

pattern

pattern to be matched against.

count

numeric vector defining counts for count-based selection.

Details

Compared with default %in% implementation in R the operators implemented here try to be more consistent with other default infix operators like == and <. In particular they preserve the dimensions and the missing values (see examples).

Style of parentheses define the type of matching template:

Value

a logical vector or an array of the same dimensions as x indicating if each value of x is within the defined subset.

See Also

%in%

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# difference in behaviour with dimensions when compared to %in%
iris[1:10,] %in% "setosa"
iris[1:10,] == "setosa"
iris[1:10,] %in{}% "setosa"

# difference in behaviour with missing values when compared to %in%
x <- c(1,2,3,NA,4)
x %in% c(1,2,3)
x %in{}% c(1,2,3)

# other interval oparators
x <- 1:10
x %in[]% c(3,7)
x %in()% c(3,7)
x %in(]% c(3,7)
x %in[)% c(3,7)
x %out[]% c(3,7)

# when more than 2 numbers are provided for the interval - range is used
x <- 1:10
all.equal(x %in[]% c(2,4), x %in[]% c(2,3,4))
all.equal(x %in[]% c(2,4), x %in[]% range(c(2,3,4)))

# matching according to regular expressions
iris$Species %in~% "^v"
iris$Species %in~f% "^v"
iris$Species %in~f% "versicolor"
iris$Species %in~f% c("versicolor", "virginica")

# selecting by number of occurances
mtcars$gear %in#% 1:5
mtcars$gear %out#% 1:5

inops documentation built on Nov. 19, 2019, 5:08 p.m.