[R] give all combinations

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


Yuan Jian <jayuan2008 <at> yahoo.com> writes:

> 
> Hello,
>  
> is there a simple way to give all combinations for a given vector:
>  
> v<-c("a","b","c")
>  
> combination(v,v) becomes
> "aa","ab","ac","bb","bc","cc'
>  
> combination(v,v,v) becomes
> "aaa","aab","aac","abb",......
>  
vv<-c(outer(v,v,paste))
 vv
[1] "a a" "b a" "c a" "a b" "b b" "c b" "a c" "b c" "c c"
vvv<-c(outer(vv,v,paste)
 vvv
 [1] "a a a" "b a a" "c a a" "a b a" "b b a" "c b a" "a c a" "b c a" 
"c c a" "a a b" "b a b" "c a b" "a b b" "b b b" 
"c b b"
[16] "a c b" "b c b" "c c b" "a a c" "b a c" "c a c" 
"a b c" "b b c" "c b c" "a c c" "b c c" "c c c"

>  
> 
>       
> 	[[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.
>



More information about the R-help mailing list