[R] expand.grid() function

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Mon Jun 23 16:36:50 CEST 2008


Ken Knoblauch wrote:
>
> How about
>
> do.call("expand.grid", rep(list(c("u", "l")), 3))
>   Var1 Var2 Var3
> 1    u    u    u
> 2    l    u    u
> 3    u    l    u
> 4    l    l    u
> 5    u    u    l
> 6    l    u    l
> 7    u    l    l
> 8    l    l    l
>
>   

... which can now be nicely generalized and abstracted as

expand.grid.rep = function(x, n=1) do.call(expand.grid, rep(list(x),n))

expand.grid.rep(c("u","l"), 3)

vQ



More information about the R-help mailing list