Description Usage Arguments Details Value Examples
Constructs an iterator generates all permutations of an iterable object. By
default, full-length permutations are generated. If m
is specified,
successive m
length permutations are instead generated.
1 | ipermutations(object, m = NULL)
|
object |
vector |
m |
length of permutations. By default, full-length permutations are generated. |
The implementation is loosely based on that of Python's itertools.
iterator that generates all permutations of object
1 2 3 4 5 6 7 8 9 10 11 12 | it <- ipermutations(1:3)
iterators::nextElem(it) # c(1, 2, 3)
iterators::nextElem(it) # c(1, 3, 2)
iterators::nextElem(it) # c(3, 1, 2)
iterators::nextElem(it) # c(3, 2, 1)
iterators::nextElem(it) # c(2, 3, 1)
iterators::nextElem(it) # c(2, 1, 3)
it2 <- ipermutations(letters[1:4])
# 24 = 4! permutations of the letters a, b, c, and d
as.list(it2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.