-help
Subject: Re: [R] Simple permutation question
For your 2nd question (which also answers your first question) I use
the permn function in the combinat package, this function is nice that
in addition to generating all the permutations it will also,
optionally, run a function on each permutation fo
For your 2nd question (which also answers your first question) I use
the permn function in the combinat package, this function is nice that
in addition to generating all the permutations it will also,
optionally, run a function on each permutation for you:
> t(simplify2array( permn( c("A","B","C")
On Wed, 25 Jun 2014 14:16:08 -0700 (PDT)
Jeff Newmiller wrote:
> The brokenness of your perm.broken function arises from the attempted
> use of sapply to bind matrices together, which is not something
> sapply does.
>
> perm.fixed <- function( x ) {
>if ( length( x ) == 1 ) return( matrix( x
sorry... editing on the fly... try:
perm.fixed <- function( x ) {
if ( length( x ) == 1 ) return( matrix( x, nrow=1 ) )
lst <- lapply( seq_along( x )
, function( i ) {
cbind( x[ i ], perm.fixed( x[ -i ] ) )
}
)
do.call( rbind
The brokenness of your perm.broken function arises from the attempted use
of sapply to bind matrices together, which is not something sapply does.
perm.fixed <- function( x ) {
if ( length( x ) == 1 ) return( matrix( x, nrow=1 ) )
lst <- lapply( seq_along( x )
, function( i )
uot;
> tail(perm.ltrs)
[1] "E D A B C" "E D B A C" "E D B C A" "E D A C B" "E D C A B" "E D C B A"
>
David C
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of David L Ca
and further...
See ?Recall for how to do recursion in R.
However, it is my understanding that recursion is not that efficient
in R. A chain of function environments must be created, and this does
not scale well. (Comments from real experts welcome here).
Cheers,
Bert
Bert Gunter
Genentech Noncl
ultimate the reverse of the second, etc.
-
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Cade
I think Robert wants deterministic permutations. In the e1071
package -- load with library(e1071) -- there is a function
permutations():
Description:
Returns a matrix containing all permutations of the integers
'1:n' (one permutation per row).
Usage:
permutations(n)
Arguments:
n: N
It is called sample(,replace=F), where the default argument is sampling
without replacement.
Try
x <- c("A","B","C","D","E")
sample(x)
Brian
Brian S. Cade, PhD
U. S. Geological Survey
Fort Collins Science Center
2150 Centre Ave., Bldg. C
Fort Collins, CO 80526-8818
email: ca...@usgs.gov
tel:
10 matches
Mail list logo