[R] How to make combination data

Jan Sabee jan.sabee at gmail.com
Tue Apr 19 20:09:23 CEST 2005


Thanks you very much.
Yes, this is exactly what I want.

Best wishes,
Jan Sabee

On 4/19/05, Liaw, Andy <andy_liaw at merck.com> wrote:
> Is something like this what you're looking for?
> 
> fixSome <- function(..., fixed) {
>     fList <- list(...)
>     for (i in fixed) fList[[i]] <- fList[[i]][1]
>     do.call("expand.grid", fList)
> }
> 
> > age       <- c("young","mid","old")
> > married   <- c("no","yes")
> > income    <- c("low","high","medium")
> > gender    <- c("female","male")
> >
> > age.income.dat <- fixSome(age, married, income, gender, fixed=c(2, 4))
> > age.income.dat
>    Var1 Var2   Var3   Var4
> 1 young   no    low female
> 2   mid   no    low female
> 3   old   no    low female
> 4 young   no   high female
> 5   mid   no   high female
> 6   old   no   high female
> 7 young   no medium female
> 8   mid   no medium female
> 9   old   no medium female
> 
> Andy




More information about the R-help mailing list