fast2waytable | R Documentation |
Contingency tables of two vectors in a much faster way than the
default table
.
fast2waytable(x, y, levels = NULL)
x , y |
two vectors of the same length with integers (or values that can be coerced to). |
levels |
the unique values found in both vectors. |
If levels
is known (and given), the running times are
considerably shorter (up to several ten times, see examples).
NA
's are not handled in this version.
a square matrix with the counts.
Emmanuel Paradis
table
, tabulate
z <- 11:20 * 10L
n <- 13e6
x <- sample(z, n, TRUE)
y <- sample(z, n, TRUE)
system.time(res1 <- fast2waytable(x, y)) # ~ 0.4 sec
system.time(res2 <- fast2waytable(x, y, z)) # ~ 0.02 sec
system.time(res3 <- table(x, y)) # ~ 1.8 sec
all(res1 == res2)
all(res1 == res3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.