Re: [R] expand.grid() function

From: Wacek Kusnierczyk <Waclaw.Marcin.Kusnierczyk_at_idi.ntnu.no>
Date: Mon, 23 Jun 2008 16:36:50 +0200

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



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 23 Jun 2008 - 14:53:19 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 23 Jun 2008 - 15:00:51 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive