you could try the following: # here with 10 instead of 50 ind <- t(combn(10, 5)) nind <- nrow(ind) cbn <- rep(0, 10 * nind) dim(cbn) <- c(nind, 10) for (i in 1:nind) { cbn[cbind(i, ind[i, ])] <- 1 } cbn rowSums(cbn)
I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm ----- Original Message ----- From: "francogrex" <[EMAIL PROTECTED]> To: <r-help@r-project.org> Sent: Friday, November 16, 2007 12:35 PM Subject: [R] expand.grid overflows? > >>cbn<-as.matrix(expand.grid( rep( list(0:1), 50))) > > Error in rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) : > invalid 'times' value > In addition: Warning message: > In rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) : > NAs introduced by coercion > > But I'm only interested in cbn matrix rows where: > cbn<- cbn[rowSums(cbn)==5,] > > Is there a way to evaluate it row by row and only store where the > sum is > equal to 5, maybe it reduces cost of computation? > -- > View this message in context: > http://www.nabble.com/expand.grid-overflows--tf4820635.html#a13791428 > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.