Dear All, I'm trying to do a simple task (which is in fact a tiny part of a larger code).
I want to create a matrix, D, each of its columns is a sequence from 0 to (n-m), by 1. Then, using D, I want to create another matrix ED, whose rows represent all the possible combinations of the elements of the columns of D. Then from ED, I'll select only the rows whose sum is less than or equal to (n-m), which will be called the matrix s. I used the following code: > n=5 > m=3 > D<-matrix(0,nrow=n-m+1,ncol=m-1) > for (i in 1:m-1) + { + D[,i]<-seq(0,n-m,1) + } > ED <- do.call(`expand.grid`,as.data.frame(D)) > ED<-as.matrix(ED) > lk<-which(rowSums(ED)<=(n-m)) > s<-ED[lk,] This works perfectly well. But for rather larger values of n and m (which are not so large actually), the number of all possible combinations of the columns of D gets extremely large giving me this error (for n=25, m=15): > ED <- do.call(`expand.grid`,as.data.frame(D)) 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 to integer range Any help or suggestions will be greatly appreciated. Thanks, Maram Salem [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.