Skip to content

give all combinations

1 message · robin hankin

#
Hi Yuan, Lucien, List.

try this:


f <-
function (...)
{
    args <- list(...)
    if(length(args)==0){
        return(NULL)
    }
    if (length(args) == 1) {
        return(args[[1]])
    }
    if (length(args) > 2) {
        jj <- do.call("Recall", c(args[-1]))
        return(do.call("Recall", c(list(args[[1]]), list(jj) )))
    }
    a <- args[[1]]
    b <- args[[2]]
    if (is.null(b)) {
        return(a)
    }
    jj <- outer(a,b,paste)
    return(jj[!lower.tri(jj)])
}



[the difficult bit (IMO) is to make f() work with any number of 
arguments; thus
f(a,a) and f(a,a,a,a,a,b,b,a,b) and whatever should also work and this 
is why
the Recall bit is needed].

Comments anyone?




HTH

rksh
Lucien Lemmens wrote: