Re: [R] Permutations

From: ONKELINX, Thierry <Thierry.ONKELINX_at_inbo.be>
Date: Tue, 13 May 2008 10:15:49 +0200

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




ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx_at_inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

-----Oorspronkelijk bericht-----
Van: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] Namens Elke Moons
Verzonden: dinsdag 13 mei 2008 9:49
Aan: r-help_at_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)

}

}

}

}

}

}

}

}

}

}

}

}

}

}

}

}

}

}

}

}

}


Elke Moons, PhD

Transportation Research Institute/

Instituut voor Mobiliteit (IMOB)

Wetenschapspark 1, bus 15

3590 Diepenbeek

BELGIUM Tel. +32-11-26.91.26

Fax. +32-11-26.91.99

E-mail: elke.moons_at_uhasselt.be

        [[alternative HTML version deleted]]



R-help_at_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.

R-help_at_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. Received on Tue 13 May 2008 - 08:29:36 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 13 May 2008 - 08:30:37 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive