EDIT
, combn(1:3, 2, simplify = FALSE) , . @Ramnath , .
> combn(1:3, 2, simplify = FALSE)
#
#
#
#
#
#
, *apply .
@Ramnath, :
enum.choose <- function(x, k) {
if(k > length(x)) stop('k > length(x)')
if(choose(length(x), k)==1){
list(as.vector(combn(x, k)))
} else {
cbn <- combn(x, k)
lapply(seq(ncol(cbn)), function(i) cbn[,i])
}
}
:
> enum.choose(1:3, 2)
# [[1]]
# [1] 1 2
#
# [[2]]
# [1] 1 3
#
# [[3]]
# [1] 2 3
> enum.choose(c(1, 2, 5, 4), 3)
# [[1]]
# [1] 1 2 5
#
# [[2]]
# [1] 1 2 4
#
# [[3]]
# [1] 1 5 4
#
# [[4]]
# [1] 2 5 4
> enum.choose(1:4, 4)
# [[1]]
# [1] 1 2 3 4
> enum.choose(1:5, 6)
# Error in enum.choose(1:5, 6) : k > length(x)