Message-ID: <1356009213.1288.YahooMailNeo@web142601.mail.bf1.yahoo.com>
Date: 2012-12-20T13:13:33Z
From: arun
Subject: permutation of vectors (1 or 0)
In-Reply-To: <1356007944700-4653607.post@n4.nabble.com>
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.