[R] give all combinations

Lucien Lemmens lucien.lemmens at ua.ac.be
Sun Aug 31 15:57:43 CEST 2008


 

Another solution requiring also a bit of programming is:

 l<-letters[1:3]
 c2<-c()
 for(i in 1:3){c2<-c(c2,paste(letters[i],letters[i:3],sep=""))}
 c2
[1] "aa" "ab" "ac" "bb" "bc" "cc"
 n<-length(c2)
 c3<-c();for(i in 1:n){c3<-c(c3,paste(c2[i],letters[ceiling(i/2):3],sep=""))}
 c3
 [1] "aaa" "aab" "aac" "aba" "abb" "abc" "acb" "acc" "bbb" "bbc" "bcc" "ccc"



More information about the R-help mailing list