[R] permutation of vectors (1 or 0)

arun smartpink111 at yahoo.com
Thu Dec 20 14:13:33 CET 2012


HI,

library(gtools)
If you need ?combinations()
combinations(2,10,0:1,repeats.allowed=TRUE)
#      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 #[1,]    0    0    0    0    0    0    0    0    0     0
 #[2,]    0    0    0    0    0    0    0    0    0     1
 #[3,]    0    0    0    0    0    0    0    0    1     1
 #[4,]    0    0    0    0    0    0    0    1    1     1
 #[5,]    0    0    0    0    0    0    1    1    1     1
 #[6,]    0    0    0    0    0    1    1    1    1     1
 #[7,]    0    0    0    0    1    1    1    1    1     1
 #[8,]    0    0    0    1    1    1    1    1    1     1
 #[9,]    0    0    1    1    1    1    1    1    1     1
#[10,]    0    1    1    1    1    1    1    1    1     1
#[11,]    1    1    1    1    1    1    1    1    1     1
#or permutations()
permutations(2,10,0:1,repeats.allowed=TRUE)
A.K.






----- Original Message -----
From: olga30dec <olga at herenstraat.nl>
To: r-help at r-project.org
Cc: 
Sent: Thursday, December 20, 2012 7:52 AM
Subject: [R] permutation of vectors (1 or 0)

Dear all,

I have 2 vectors of 10 elements, each of them contains either 0 or 1, like
following:

> Null<-rep(0,10)
> Null
[1] 0 0 0 0 0 0 0 0 0 0

> One<-rep(1,10)
> One
[1] 1 1 1 1 1 1 1 1 1 1

How can I obtain a matrix rows of which can take all possible combinations?

e.g.
0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0
...
0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 1 1
1 1 1 1 1 1 1 1 1 1

Many thanks,
Olga




--
View this message in context: http://r.789695.n4.nabble.com/permutation-of-vectors-1-or-0-tp4653607.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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