Well, this is a natural thing to program up using 3 nested 'for',
loops. Alternatively, one could use something like:
> combn <- function( ..., l=list(...) )
+ {
+ lens <- sapply( args, length)
+ ncomb <- prod(lens)
+ retval <- matrix(ncol=length(args), nrow=ncomb)
+ for(i in 1:leng
] sequence of vectors
Dear All,
I wonder if there is any R function to generate a sequence of vectors
from existing ones. For example:
x 1<- c(1,2,3)
x2 <- c(4,5)
x3 <- c(6,7,8)
The desired output is a list of all 3*2*3 = 18 possible combinations
of elements of x1,x2 an
://www.student.kuleuven.be/~m0390867/dimitris.htm
- Original Message -
From: "Marc Bernard" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, November 19, 2007 3:59 PM
Subject: [R] sequence of vectors
> Dear All,
>
> I wonder if there is any R fun
?expand.grid should do what you want.
--- Marc Bernard <[EMAIL PROTECTED]> wrote:
> Dear All,
>
> I wonder if there is any R function to generate a
> sequence of vectors from existing ones. For example:
> x 1<- c(1,2,3)
> x2 <- c(4,5)
> x3 <- c(6,7,8)
>
> The desired output is
Dear All,
I wonder if there is any R function to generate a sequence of vectors from
existing ones. For example:
x 1<- c(1,2,3)
x2 <- c(4,5)
x3 <- c(6,7,8)
The desired output is a list of all 3*2*3 = 18 possible combinations of
elements of x1,x2 and x3. One element for example i
5 matches
Mail list logo