Skip to content
Prev 336163 / 398502 Next

match - returns a vector of the positions of (first) matches - looking for All positions.

How is this different than
   which( table == "a")
?  The latter is probably a tad faster.

I thought the OP had 2 vectors, x and table, and wanted a list the length
of x, such that the i'th element of the list gave the positions of the elements
of the table that matched x[i].  I don't know why this would be useful, but a
naive implementation would be
    f <- function(x, table)lapply(structure(x, names=x), function(xi)which(table == xi))
 used as
   > t1 <- c("a", "b", "a", "c", "b")
   > t2 <- c("b", "b", "c", "d", "c")
   > f(t1, t2)
   $a
   integer(0)

   $b
   [1] 1 2

   $a
   integer(0)
   
   $c
   [1] 3 5
   
   $b
   [1] 1 2

Bill Dunlap
TIBCO Software
wdunlap tibco.com