From: Luís Torgo <ltorgo_at_liacc.up.pt>

Date: Thu 09 Feb 2006 - 05:08:40 EST

getVariant <- function(id,vars) {

> expand.grid(par1=-1:1,par2=c('a','b'))[4,]

par1 par2

4 -1 b

> getVariant(4,list(par1=-1:1,par2=c('a','b')))

$par1

[1] -1

Date: Thu 09 Feb 2006 - 05:08:40 EST

Now, the function I've created was the following:

getVariant <- function(id,vars) {

if (!is.list(vars)) stop('vars needs to be a list!')

nv <- length(vars)

lims <- sapply(vars,length)

if (id > prod(lims)) stop('id above the number of combinations!')

res <- vector("list",nv)

for(i in nv:2) {

res[[i]] <- vars[[i]][ceiling(id / f)]

id <- id - (ceiling(id/f)-1)*f

}

res[[1]] <- vars[[1]][id]

names(res) <- names(vars)

res

}

> expand.grid(par1=-1:1,par2=c('a','b'))[4,]

par1 par2

4 -1 b

> getVariant(4,list(par1=-1:1,par2=c('a','b')))

$par1

[1] -1

$par2

[1] "b"

I would be glad to know if somebody came across the same problem and has a better suggestion on how to solve this.

Thanks,

Luis

-- Luis Torgo FEP/LIACC, University of Porto Phone : (+351) 22 339 20 93 Machine Learning Group Fax : (+351) 22 339 20 99 R. de Ceuta, 118, 6o email : ltorgo@liacc.up.pt 4050-190 PORTO - PORTUGAL WWW : http://www.liacc.up.pt/~ltorgo ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.htmlReceived on Thu Feb 09 06:45:32 2006

*
This archive was generated by hypermail 2.1.8
: Fri 03 Mar 2006 - 03:42:26 EST
*