searchListOfVectors: Search List of Vectors

Description Usage Arguments Details Value Examples

Description

Search List of Vectors

Usage

1
searchListOfVectors(q, lst, useNames = FALSE, queryAll = FALSE)

Arguments

q

query vector

lst

list of vectors to search

useNames

return names rather than indicies; ignored if no names. Default: FALSE

queryAll

query for union of q entries

Details

Taken from: http://stackoverflow.com/questions/11002391/fast-way-of-getting-index-of-match-in-list

Value

a list of vectors with the same length as the query vector, each list entry will have indicies for lst where there was a match with the query vector. Return NA if there were no matches.

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
33
34
35
36
37
38
39
40
41
42
43
44
45
lst <- list(1:3, 3:5, 3:7)
q <- c(3, 5)
results <- searchListOfVectors(q, lst)
names(results) <- q

lst <- list(LETTERS[1:3], LETTERS[3:5], LETTERS[3:7])
q <- c("C", "E")
searchListOfVectors(q, lst)

lst <- list(LETTERS[3], LETTERS[4:6])
q <- "C"
searchListOfVectors(q, lst)

lst <- list(LETTERS[3], LETTERS[4:6])
q <- c("C")
searchListOfVectors(q, lst)

lst <- list(LETTERS[3], LETTERS[4:6])
q <- c("C", "E")
searchListOfVectors(q, lst)

lst <- list(a=LETTERS[3], b=LETTERS[4:6])
q <- c("C", "E")
searchListOfVectors(q, lst, useNames=TRUE)

lst <- list(a=LETTERS[3], b=LETTERS[3:6])
q <- c("C", "E")
searchListOfVectors(q, lst, useNames=TRUE)

lst <- list(LETTERS[3], LETTERS[4:6])
q <- "Z"
searchListOfVectors(q, lst)

lst <- list(a=LETTERS[3], b=LETTERS[3:6])
q <- c("C", "E")
searchListOfVectors(q, lst, useNames=TRUE, queryAll=TRUE)

lst <- list(a=LETTERS[3], b=LETTERS[3:6])
q <- c("C", "E")
searchListOfVectors(q, lst, useNames=FALSE, queryAll=TRUE)

#lst <- list(LETTERS[3], LETTERS[3:6])
#q <- c("C", "E")
#searchListOfVectors(q, lst, useNames=TRUE, queryAll=TRUE)
  

cannin/listutils documentation built on May 24, 2019, 9:53 a.m.