Skip to content
Prev 324587 / 398503 Next

Frequency count of Boolean pattern in 4 vectors.

For 10 million data points
   table(interaction(vec_D, vec_C, vec_B, vec_A))
took my laptop 11.45 seconds and the following function required 0.18 seconds
   f0 <- function (vec_A, vec_B, vec_C, vec_D) 
  {
      x <- 1 + vec_A + 2 * (vec_B + 2 * (vec_C + 2 * vec_D))
      tab <- tabulate(x, nbins = 16)
      names(tab) <- do.call(paste0, rev(expand.grid(0:1, 0:1, 0:1, 
          0:1)))
      tab
  }
Aside from the order of the entries in the output tables, they gave the same results.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com