ipermutations {iterors}R Documentation

Iterator that generates all permutations of a vector.

Description

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.

Usage

ipermutations(object, m = NULL)

Arguments

object

vector

m

length of permutations. By default, full-length permutations are generated.

Details

The implementation is loosely based on that of Python's itertools.

Value

iterator that generates all permutations of object

Examples

it <- ipermutations(1:3)

nextOr(it, NA) # c(1, 2, 3)
nextOr(it, NA) # c(1, 3, 2)
nextOr(it, NA) # c(3, 1, 2)
nextOr(it, NA) # c(3, 2, 1)
nextOr(it, NA) # c(2, 3, 1)
nextOr(it, NA) # c(2, 1, 3)

it2 <- ipermutations(letters[1:4])
# 24 = 4! permutations of the letters a, b, c, and d
as.list(it2)


[Package iterors version 1.0 Index]