You have tried gtools::combinations(3,2,letters[1:3])
? On Sun, Sep 6, 2009 at 2:10 PM, Grzes <gregori...@gmail.com> wrote: > > Hi! > I want to use one method "combinations" from "gtools" package but in my > code > I must use also "dprep" method where is method "combinations" too. Mayby I > show you result of help function: > > Help on topic 'combinations' was found in the following packages: > > Package Library > dprep /usr/lib64/R/library > gtools /usr/lib64/R/library > > Choose one > > 1: Constructing distinct permutations {dprep} > 2: Enumerate the Combinations or Permutations of the Elements of a Vector > {gtools} > > > If I want to use "combination" method I use error: > > > combinations(3,2,letters[1:3]) > Error in combinations(3, 2, letters[1:3]) : > unused argument(s) (2, letters[1:3]) > > Do you have any idea? > I try code similar to C++ gtools::combinations but in my opinion it's > wrong way. > > If my explanation is't clear to you let me show my all attempts: > > > > library(gtools) > > combinations(3,2,letters[1:3]) > [,1] [,2] > [1,] "a" "b" > [2,] "a" "c" > [3,] "b" "c" > > library(dprep) > Loading required package: MASS > Loading required package: nnet > Loading required package: lattice > Loading required package: class > > Attaching package: 'dprep' > > > The following object(s) are masked from package:gtools : > > combinations > > > combinations(3,2,letters[1:3]) > Error in combinations(3, 2, letters[1:3]) : > unused argument(s) (2, letters[1:3]) > > > gtools::combinations > function (n, r, v = 1:n, set = TRUE, repeats.allowed = FALSE) > { > if (mode(n) != "numeric" || length(n) != 1 || n < 1 || (n%%1) != > 0) > stop("bad value of n") > if (mode(r) != "numeric" || length(r) != 1 || r < 1 || (r%%1) != > 0) > stop("bad value of r") > if (!is.atomic(v) || length(v) < n) > stop("v is either non-atomic or too short") > if ((r > n) & repeats.allowed == FALSE) > stop("r > n and repeats.allowed=FALSE") > if (set) { > v <- unique(sort(v)) > if (length(v) < n) > stop("too few different elements") > } > v0 <- vector(mode(v), 0) > if (repeats.allowed) > sub <- function(n, r, v) { > if (r == 0) > v0 > else if (r == 1) > matrix(v, n, 1) > else if (n == 1) > matrix(v, 1, r) > else rbind(cbind(v[1], Recall(n, r - 1, v)), Recall(n - > 1, r, v[-1])) > } > else sub <- function(n, r, v) { > if (r == 0) > v0 > else if (r == 1) > matrix(v, n, 1) > else if (r == n) > matrix(v, 1, n) > else rbind(cbind(v[1], Recall(n - 1, r - 1, v[-1])), > Recall(n - 1, r, v[-1])) > } > sub(n, r, v[1:n]) > } > <environment: namespace:gtools> > > > combinations(3,2,letters[1:3]) ### what I should do to > > start working "combinations"? > Error in combinations(3, 2, letters[1:3]) : > unused argument(s) (2, letters[1:3]) > -- > View this message in context: > http://www.nabble.com/Two-packages-ane-one-method-tp25319739p25319739.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
______________________________________________ R-help@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.