Skip to contents

Match all positions of an argument

Usage

matchAll(x, table, ...)

# S4 method for character,character
matchAll(x, table, simplify = FALSE)

# S4 method for factor,factor
matchAll(x, table, simplify = FALSE)

# S4 method for numeric,numeric
matchAll(x, table, simplify = FALSE)

Arguments

x

The values to be matched.

table

The values to be matched against.

simplify

logical(1). Unlist match list into a positional vector.

...

Additional arguments.

Value

list. A list of positional vectors corresponding to values defined in table the same size as x.

Details

matchAll() behaves like base match(), but is intended to return a list of all position matches of the argument defined in x.

Note

Updated 2023-12-15.

Examples

## character ====
x <- c("c", "b", "a")
table <- c("a", "b", "c", "a", "b", "c")
i <- matchAll(x = x, table = table, simplify = FALSE)
print(i)
#> [[1]]
#> [1] 3 6
#> 
#> [[2]]
#> [1] 2 5
#> 
#> [[3]]
#> [1] 1 4
#> 
i <- matchAll(x = x, table = table, simplify = TRUE)
print(i)
#> [1] 3 6 2 5 1 4