library(partitions)
x <- c(2,4,6) # Substitute the vector for which you want partitions
parts <- listParts(length(x))
out <- rapply(parts, function(ii) x[ii], how="replace")
# This step is for cosmetic purposes only. It allows you to take advantage of
# the `print.equivalence` print method when printing the object to a console
for(i in seq_along(out)) class(out[[i]]) <- c("list", "equivalence")
out
[[1]]
[1] (2,4,6)
[[2]]
[1] (2,6)(4)
[[3]]
[1] (2,4)(6)
[[4]]
[1] (4,6)(2)
[[5]]
[1] (2)(4)(6)
另请参见同一包中的setparts(),以更紧凑的方式表示同一组分区。
0
这是否能为您提供所需的东西,
install.packages("gregmisc", dependencies = TRUE)
library(gregmisc)
x <- c(1,2,3,4,5)
for(i in 1:length(x)) {
print(combinations(5,i,x,repeats=TRUE))
}
2 回答
这是一个解决方案,可为您提供完整的分区列表,每个分区均表示为向量列表。由于列表列表在打印到屏幕上时非常难看,因此我还向您展示了如何获得打印效果更好的对象。
另请参见同一包中的
setparts()
,以更紧凑的方式表示同一组分区。这是否能为您提供所需的东西,