# [R] ellipsis question

Robin Hankin r.hankin at auckland.ac.nz
Tue Mar 26 22:18:09 CET 2002

```Hello R experten

I have just written a little function to calculate all pairwise
combinations of two vector arguments:

> pair(c(1,2,3),c(7,8))
[,1] [,2]
[1,]    1    7
[2,]    1    8
[3,]    2    7
[4,]    2    8
[5,]    3    7
[6,]    3    8
>

I want to generalize this to any number of arguments, for example,

<fantasy>

> ntuple(c(1,2,3),c(7,8),c(14,15))
[,1] [,2] [,3]
[ 1,]    1    7   14
[ 2,]    1    8   14
[ 3,]    2    7   14
[ 4,]    2    8   14
[ 5,]    3    7   14
[ 6,]    3    8   14
[ 7,]    1    7   15
[ 8,]    1    8   15
[ 9,]    2    7   15
[10,]    2    8   15
[11,]    3    7   15
[12,]    3    8   15

</fantasy>

One object is to have b <- c(0,1) and then ntuple(b,b,b,b,b,b,b,b)
will generate all 256 distinct bytes.

I tried to use the ellipsis argument "..." with no success (because it
takes only named arguments).  Any help anyone?  While I'm writing, my
meshgrid() below works as per octave's, but it's a bit clunky.  Is
there anything better?

This is the only thing I've found so far that Octave can do that I
can't easily replicate in R.

===work done so far===

meshgrid <- function(x,y) {
ignore.arg2 <- function(x,y) {x}
list(x=t(outer(x,y,FUN=ignore.arg2)),y=outer(y,x,FUN=ignore.arg2))
}

pair <- function(a,b) {
len <- length(a) * length(b)
jj <- meshgrid(a,b)
cbind(as.vector(jj\$x),as.vector(jj\$y))
}

ntuple <- function(a,b, ...) {
#help help how do I do this
}

--

Robin Hankin, Lecturer,
School of Geographical and Environmental Science
Private Bag 92019 Auckland
New Zealand

r.hankin at auckland.ac.nz
tel 0064-9-373-7599 x6820; FAX 0064-9-373-7042

as of: Wed Mar 27 09:15:00 NZST 2002
This (linux) system up continuously for:  209 days, 16 hours, 10 minutes
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```