Re: [R] Combinations with two part column

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Wed 18 May 2005 - 06:53:14 EST

Try write.table:

write.table(comb8.5[,1:5], sep = ",", row.names = FALSE, col.names = FALSE) write.table(comb8.5[,6:8], sep = ",", row.names = FALSE, col.names = FALSE)

On 5/17/05, Sofyan Iyan <sofyan.iyan@gmail.com> wrote:
> Thanks for you quick answer.
> Could I extend my question?
> How to make the result for each rows with comma ",";
> > library(gtools)
> > comb8.5 <- t(apply(combinations(8,5), 1, function(x) c(x,setdiff(1:8, x))))
> > comb8.5[,1:5]
> [,1] [,2] [,3] [,4] [,5]
> [1,] 1 2 3 4 5
> [2,] 1 2 3 4 6
> [3,] 1 2 3 4 7
> [4,] 1 2 3 4 8
> [5,] 1 2 3 5 6
> [6,] 1 2 3 5 7
> ...
>
> I mean like:
> 1, 2, 3, 4, 5
> 1, 2, 3, 4, 6
> 1, 2, 3, 4, 7
> 1, 2, 3, 4, 8
> 1, 2, 3, 5, 6
> 1, 2, 3, 5, 7
>
> > comb8.5[,6:8]
> [,1] [,2] [,3]
> [1,] 6 7 8
> [2,] 5 7 8
> [3,] 5 6 8
> [4,] 5 6 7
> [5,] 4 7 8
> [6,] 4 6 8
> ...
>
> this below like:
> 6, 7, 8
> 5, 7, 8
> 5, 6, 8
> 5, 6, 7
> 4, 7, 8
> 4, 6, 8
>
> Best,
> Sofyan
>
>
> On 5/17/05, Gabor Grothendieck <ggrothendieck@gmail.com> wrote:
> > On 5/17/05, Sofyan Iyan <sofyan.iyan@gmail.com> wrote:
> > > Dear R-helpers,
> > > I am a beginner using R.
> > > This is the first question in this list.
> > > My question, Is there possible to make combinations with two part column?
> > > If I have a number 1,2,3,4,5,6,7,8. I need the result something like below:
> > >
> > > 1,2,3,4,5 6,7,8
> > > 1,2,3,4,7 5,6,8
> > > 2,3,4,5,6 1,7,8
> > > 1,2,3,6,7 4,5,8
> > > 1,2,3,4,8 5,6,7
> > > 3,4,6,7,8 1,2,5
> > > ....
> > >
> >
> > Try this:
> >
> > library(gtools)
> > t(apply(combinations(8,5), 1, function(x) c(x,setdiff(1:8, x))))
> >
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed May 18 06:57:54 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:50 EST