Re: [R] Build Design Matrix with avoiding loops

2010-06-04 Thread Erik Iverson
help.search("design matrix") will lead you to ?model.matrix ... Gildas Mazo wrote: Dear R users, I'd like to build a simple design matrix in a efficient way. I naively wrote the code below. n = 15 k = 3 nbPerGrp = c(5,5,5) xT <- list() for (i in 1:k){ xT[[i]] <- rep(0, k)

Re: [R] Build Design Matrix with avoiding loops

2010-06-04 Thread Martyn Byng
Hi, Something like x = as.factor(rep(1:k,rep(n/k,k)) X = model.matrix(~x-1) Might be what you are looking for Martyn -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Gildas Mazo Sent: 04 June 2010 16:19 To: r-help@r-project.org Su