Learn R Programming

arrangements (version 1.0.0)

Partitions: Partitions iterator

Description

This function returns a Partitions iterator which allows users to fetch the next partition(s) via the getnext() method. All remaing partitions of the iterator can be fetched via the collect() method.

Usage

Partitions

ipartitions(n, k = NULL, descending = FALSE)

Arguments

n

an non-negative integer to be partitioned

k

number of parts

descending

logical to use reversed lexicographical order

Format

An object of class R6ClassGenerator of length 24.

Details

The Partitions class can be initialized by using the convenient wrapper ipartitions or

Partitions$new(n, k = NULL, descending = FALSE)

getnext(d = 1L, type = NULL, drop = d == 1L && is.null(type))
collect(type = "r")
reset()
d

number of fetched arrangements

type

if "r", "c" or "l" is specified, the returned value would be a "row-major" matrix, a "column-major" matrix or a list respectively

drop

vectorize a matrix or unlist a list

See Also

partitions for generating all partitions and npartitions to calculate number of partitions

Examples

Run this code
# NOT RUN {
ipart <- ipartitions(10)
ipart$getnext()
ipart$getnext(2)
ipart$getnext(type = "c", drop = FALSE)
# collect remaining partitions
ipart$collect()

library(foreach)
foreach(x = ipartitions(6, 2), .combine=c) %do% {
  prod(x)
}
# }

Run the code above in your browser using DataLab