Fast Combinations and Permutations in R.
The fastpeRmute
package offers efficient functions for computing combinations and permutations with and without repetition in R. The underlying implementation leverages C++ for optimal performance, making it potentially faster than both base R and other packages like gtools.
To install the latest development version from GitHub:
devtools::install_github("gi0na/fastpeRmute")
library(fastpeRmute)
combinations(n = 10, r = 4)
combinations(n = 10, r = 4, repeats.allowed = TRUE)
permutations(n = 4, r = 2)
permutations(n = 4, r = 2, repeats.allowed = TRUE)
You can also generate combinations or permutations from specific vectors:
v = letters
combinations(v=v, r = 3)
v = letters[1:4]
permutations(v=v, r = 2)
v <- mapply(v1 = letters[1:4], v2 = sample(LETTERS)[1:4], FUN = function(v1, v2) c(v1, v2), SIMPLIFY = FALSE)
combinations(v=v, r = 3, out_format = 'tibble')
v <- mapply(v1 = letters[1:4], v2 = sample(LETTERS)[1:4], FUN = function(v1, v2) c(v1, v2), SIMPLIFY = FALSE)
permutations(v=v, r = 2, out_format = 'tibble')
Feedback, contributions, and issues are welcome on the GitHub repository.