deduped | R Documentation |
Converts a vectorized function into one that only performs the computations on unique values in the first argument. The result is then expanded so that it is the same as if the computation was performed on all elements.
deduped(f)
f |
Function that accepts a vector or list as its first input. |
Deduplicated version of f
.
x <- sample(LETTERS, 10)
x
large_x <- sample(rep(x, 10))
length(large_x)
slow_func <- function(x) {
for (i in x) {
Sys.sleep(0.001)
}
}
system.time({
y1 <- slow_func(large_x)
})
system.time({
y2 <- deduped(slow_func)(large_x)
})
all(y1 == y2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.