swh:1:snp:81eadaa089e8253d8469bcef66aa332632c6c669
Tip revision: c1688b374d201c13fb40b4dda2d2a89e34b94ec6 authored by Hans W. Borchers on 23 January 2021, 09:10:02 UTC
version 2.3.3
version 2.3.3
Tip revision: c1688b3
combs.R
##
## c o m b s . R Combinations
##
combs <- function(a, m){
n <- length(a)
if (length(a) == 0 || m <= 0) return(c())
if (m >= n) return(a)
if (m <= 1) return(matrix(a, n, 1))
v <- c(a)
P <- c()
for (k in 1:(n-m)) {
Q <- combs(v[(k+1):n], m-1)
P <- rbind(P, cbind(v[k], Q))
}
k <- n-m+1
Q <- combs(v[(k+1):n], m-1)
P <- rbind(P, c(v[k], Q))
b <- a[c(P)]
dim(b) <- dim(P)
return(P)
}
randcomb <- function(a, m) {
n <- length(a)
if (n == 0) return(c())
m <- sample(1:n, size = m, replace = FALSE)
return(a[m])
}