Hi there!
Here's another variation on the theme:
> grid1
function(x, n = length(x))
{
y <- rep(cbind.data.frame(x), n)
z <- expand.grid(y)
z
}
> xa
[1] "a" "b"
> grid1(xa,3)
X1 X1 X1
1 a a a
2 b a a
3 a b a
4 b b a
5 a a b
6 b a b
7 a b b
8 b b b
Sincerely,
Erin M. Hodgess, Ph.D.
Assistant Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
One Main Street
Houston, TX 77002
e-mail: hodgess@uhdux2.dt.uh.edu
Subject: Re2: [splus-users,11557] [S] Combinatory function
In-Reply-To: <199906221414.XAA25328@cabbage.math.keio.ac.jp>
Hi!
>dd1<-seq(from=1, by=1, length=5)
>comb <- expand.grid(x1 =dd1 , x2 =dd1, x3 =dd1, x4 = dd1, x5=dd1,
>xx6=dd1)
>This program gives you all combinations of c(1,2,3,4,5).
>If you replace "1" by "a", "2" by "b",-----, "5" by "e",
>it results in all combinations of a,b,c,d,e.
Program like below may be simpler; you do not have
to replace numbers by letters :
function()
{
dd1 <- c("a", "b")
comb <- expand.grid(x1 = dd1, x2 = dd1, x3 = dd1)
print(comb)
}
Result is :
x1 x2 x3
1 a a a
2 b a a
3 a b a
4 b b a
5 a a b
6 b a b
7 a b b
8 b b b
K. Takezawa
***** Kunio Takezawa, Ph.D. (takezawa@affrc.go.jp) *****
***** Research Information Section *****
**** Hokuriku National Agricultural Experiment Station, JAPAN ****
***** <http://www.inada.affrc.go.jp/~takezawa/patent-e.html> *****
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
|