Question

Is there any implementation of integer partitioning in R?

For example for input 4 I would like to get 5 vectors:

4
3 , 1
2 , 2
2 , 1 , 1
1 , 1 , 1 , 1

There are implementations in Python, Erlang, Java, C, Perl, but I can't find anything in R.

Was it helpful?

Solution

Use the "partitions" package:

install.packages("partitions")
library(partitions)
parts(4)
#               
# [1,] 4 3 2 2 1
# [2,] 0 1 2 1 1
# [3,] 0 0 0 1 1
# [4,] 0 0 0 0 1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top