Skip to content
Prev 99111 / 398500 Next

Dividing objects in classes using function sample()

If n and k are small try brute force.

g <- expand.grid(0:4, 0:4, 0:4)
g[rowSums(g) == 4,]

or more generally:

n <- 4; k <- 3
g <- do.call(expand.grid, rep(list(0:n), k))
g[rowSums(g) == n,]
On 9/2/06, "Maja Schr?ter" <maja.schroeter at gmx.de> wrote: