[R] combinations with replications
ONKELINX, Thierry
Thierry.ONKELINX at inbo.be
Thu Jul 31 13:23:44 CEST 2008
Or simply
Datagrid <- expand.grid(rep(list(0:1), 8))
apply(Datagrid, 1, paste, collapse = "")
HTH,
Thierry
------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be
www.inbo.be
To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey
-----Oorspronkelijk bericht-----
Van: r-help-bounces op r-project.org [mailto:r-help-bounces op r-project.org]
Namens Jim Lemon
Verzonden: donderdag 31 juli 2008 13:19
Aan: MarinaTarantini
CC: r-help op r-project.org
Onderwerp: Re: [R] combinations with replications
On Thu, 2008-07-31 at 02:29 -0700, MarinaTarantini wrote:
> Dear all,
> Is there a way to compute and list all combinations with replication
of two
> elements in sets of 8 elemnts?
> For example, I've two elements, 0 and 1, and I would to get all
possible
> combinations with replication such as, for example, 00000000,
00000001,
> 00000010, and so on. They are 2^8 and it's very hard to list handly!!
Hi Marina,
Here's a Q&D solution for the specific problem that could easily be
extended to different numbers of elements (although it would blow out
very quickly)..
zero8<-rep(0,8)
oneto8<-1:8
cat(zero8,"\n")
for(i in 1:7) {
combi<-combn(oneto8,i)
combcol<-dim(combi)[2]
for(comb in 1:combcol) {
nextcomb<-zero8
nextcomb[combi[,comb]]<-1
cat(nextcomb,"\n")
}
}
cat(rep(1,8),"\n")
Jim
______________________________________________
R-help op 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