Please consider the following :> expand.grid(rep(list(c(1:3)), 3))Var1 Var2 Var3 1 1 1 1 2 2 1 1 3 3 1 1 4 1 2 1 5 2 2 1 6 3 2 1 7 1 3 1 8 2 3 1 9 3 3 1 10 1 1 2 11 2 1 2 12 3 1 2 13 1 2 2 14 2 2 2 15 3 2 2 16 1 3 2 17 2 3 2 18 3 3 2 19 1 1 3 20 2 1 3 21 3 1 3 22 1 2 3 23 2 2 3 24 3 2 3 25 1 3 3 26 2 3 3 27 3 3 3 Now I want to remove the rows which has any repetition of number. For example I want to remove row 1-5 but not 6 and so on........ Is there any easy way to do that? Thanks, -- View this message in context: http://old.nabble.com/All-combination-tp26333348p26333348.html Sent from the R help mailing list archive at Nabble.com.
have a look at function permutations from package 'e1071', e.g., library(e1071) permutations(3) I hope it helps. Best, Dimitris RON70 wrote:> Please consider the following : > >> expand.grid(rep(list(c(1:3)), 3)) > Var1 Var2 Var3 > 1 1 1 1 > 2 2 1 1 > 3 3 1 1 > 4 1 2 1 > 5 2 2 1 > 6 3 2 1 > 7 1 3 1 > 8 2 3 1 > 9 3 3 1 > 10 1 1 2 > 11 2 1 2 > 12 3 1 2 > 13 1 2 2 > 14 2 2 2 > 15 3 2 2 > 16 1 3 2 > 17 2 3 2 > 18 3 3 2 > 19 1 1 3 > 20 2 1 3 > 21 3 1 3 > 22 1 2 3 > 23 2 2 3 > 24 3 2 3 > 25 1 3 3 > 26 2 3 3 > 27 3 3 3 > > > Now I want to remove the rows which has any repetition of number. For > example I want to remove row 1-5 but not 6 and so on........ > > Is there any easy way to do that? > > Thanks,-- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014
Besides the much more compact and probably more efficient approach of using permutation, here is another method: expand.grid(rep(list(c(1:3)), 3))[ lapply( apply( expand.grid(rep(list(c(1:3)), 3)), 1, unique), length) ==3 , ] On Nov 13, 2009, at 4:02 AM, RON70 wrote:> > Please consider the following : > >> expand.grid(rep(list(c(1:3)), 3)) > Var1 Var2 Var3 > 1 1 1 1 > 2 2 1 1 > 3 3 1 1 > 4 1 2 1 > 5 2 2 1 > 6 3 2 1 > 7 1 3 1 > 8 2 3 1 > 9 3 3 1 > 10 1 1 2 > 11 2 1 2 > 12 3 1 2 > 13 1 2 2 > 14 2 2 2 > 15 3 2 2 > 16 1 3 2 > 17 2 3 2 > 18 3 3 2 > 19 1 1 3 > 20 2 1 3 > 21 3 1 3 > 22 1 2 3 > 23 2 2 3 > 24 3 2 3 > 25 1 3 3 > 26 2 3 3 > 27 3 3 3 > > > Now I want to remove the rows which has any repetition of number. For > example I want to remove row 1-5 but not 6 and so on........ > > Is there any easy way to do that? > > Thanks, > -- > View this message in context: http://old.nabble.com/All-combination-tp26333348p26333348.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.David Winsemius, MD Heritage Laboratories West Hartford, CT
Possibly Parallel Threads
- More elegant way of excluding rows with equal values in any 2 columns?
- A question to get all possible combinations
- Non repetitive permutations/combinations of elements
- converting a character vector to a function's input
- crear variable en base a nombre de columnas que tienen un 1