Hi Diane,
Does this do what you want ?
listParts <- function(n) {
# Generates a list of lists representing the partitions
# of an integer n
require(partitions)
x <- 1:n
apply(setparts(n), 2, function(pp) tapply(x, pp, function(xx) list(xx)))
}
Michael
On 12 November 2010 21:15, Diana Tichy
<d.tichy at mathematik.uni-wuerzburg.de> wrote:
Hello Michael
once again. Now I can use print.partition which tells me, how to generate,
e.g., all possible 5 partitions of {1,2,3}. But this generation is still
complicated. Does there already exist a function doing that for me, e.g.
returns a list, where the first element contains the one-elemnt partion, the
second to fourth the three 2-element-partions and the fifth the 3-element
partition?
Do you know or is it my job to implement this by myself (o.k. but
time-consuming ..)
Best wishes
Diana
Am 12.11.2010 10:32, schrieb Michael Bedward:
Hi Diana, Have a look at the setparts function in the partitions package. Michael On 12 November 2010 20:03, Diana<d.tichy at mathematik.uni-wuerzburg.de> ?wrote:
Hi
I am new on this forum. I am searching for a function in R which provides
all partitions of a set, say for the set
{1,2,3}
you get
{{1,2,3}}
{1,{2,3}}
{2,{1,3}}
{3,{1,2}}
{{1},{2},{3}}
. The number of partitions of a set is given by Bellsche`s number. The
number of possibilities of length (this is the number of subsets included
in
the partition) of the partition is given by the partition function.
But I need a list containg all possible partitions of an index set
{1,...,d}, d arbitrary.
I have already looked at the FAQs but I did not found. Sorry.
Can anybody help me?
Thanks a lot!
Diana Tichy
--
View this message in context:
http://r.789695.n4.nabble.com/Partition-of-a-set-tp3039291p3039291.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
-- Diana Tichy (geb. St?hr) Lehrstuhl f?r Statistik Institut f?r Mathematik Universit?t W?rzburg Am Hubland 97074 W?rzburg Raum R110, Mathematikgeb?ude Tel.: 0931-31 85027 d.tichy at mathematik.uni-wuerzburg.de http://statistik.mathematik.uni-wuerzburg.de/~tichy