Hi Elke, the matrix you are trying to create has 5^21 = 476837158203125 rows and 21 columns. I'm afraid Thierry's proposal with n=21 will not fit into memory. And the file you are writing is 5^21*5*8 bytes big, about 80108643 GB.
Perhaps you want to think a little more about what you are trying to achieve and, e.g., consider random sampling from the matrix? In addition, look at your code: you append every single line to the output file, i.e., you open and close your file 5^21 = 476837158203125 times. File I/O always takes a lot of time. File I/O in a loop usually leads to slow execution. HTH, Stephan ONKELINX, Thierry schrieb: > Dear Elke, > > I think you need something like this. It's only for 3 variables, but I > think you know how to expand it for more variables. > > mat <- expand.grid(a = 0:4, b = 0:4, c = 0:4) > write.table(mat, file="C:/Documents and Settings/My > Documents/permutations.txt",sep=";",col.names=FALSE, row.names=FALSE) > > HTH, > > Thierry > Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Namens Elke Moons > Verzonden: dinsdag 13 mei 2008 9:49 > Aan: r-help@r-project.org > Onderwerp: [R] Permutations > > Dear R-users, > > > > > > Is there an easy way to determine all possible vectors of length 21 with > each entry having permutations from 0 to 4, instead of doing it like > this? > It really takes up too much time, and I am convinced that there exists > something easier. > > Can you help me? Thank you in advance! > > Kind regards, > > > > > > Elke > > > > for (a in 0:4){ > > for (b in 0:4){ > > for (c in 0:4){ > > for (d in 0:4){ > > for (e in 0:4){ > > for (f in 0:4){ > > for (g in 0:4){ > > for (h in 0:4){ > > for (i in 0:4){ > > for (j in 0:4){ > > for (k in 0:4){ > > for (l in 0:4){ > > for (m in 0:4){ > > for (n in 0:4){ > > for (o in 0:4){ > > for (p in 0:4){ > > for (q in 0:4){ > > for (r in 0:4){ > > for (s in 0:4){ > > for (u in 0:4){ > > for (v in 0:4){ > > vec<-list(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,u,v) > > write.table(vec,file="C:/Documents and Settings/My > Documents/permutations.txt",sep=";",col.names=FALSE, row.names=FALSE, > append=TRUE) > > } > > } > > } > > } > > } > > } > > } > > } > > } > > } > > } > > } > > } > > } > > } > > } > > } > > } > > } > > } > > } -- ______________________________________________ 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.