3

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.

Community
  • 1
  • 1
Tomas Greif
  • 21,685
  • 23
  • 106
  • 155
  • `library("sos"); findFn("partitions")` finds a few too many hits, but the third package listed is the `partitions` package referred to by @AnandaMahto ... – Ben Bolker Sep 06 '13 at 22:17

1 Answers1

7

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
A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485