thanks. how to remove the combinations that has same ingredients: v<-c("a","b","c") v.v becomes ab, ac, bc (aa,bb,cc are removed) v.v.v becomes abc (aaa,aab,... are removed, because they have same ingredients) that is. the following sentences can be used. for(i in 1:3){ for (j in i+1:3){ v.v<-c(v.v,paste(v[i],v[j])) } }
is there simpler way to do? thanks Yu --- On Sun, 8/31/08, Lucien Lemmens <[EMAIL PROTECTED]> wrote: From: Lucien Lemmens <[EMAIL PROTECTED]> Subject: Re: [R] give all combinations To: [EMAIL PROTECTED] Date: Sunday, August 31, 2008, 8:38 AM 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. > ______________________________________________ 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. [[alternative HTML version deleted]]
______________________________________________ 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.