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 for you:
t
On Wed, 25 Jun 2014 14:16:08 -0700 (PDT)
Jeff Newmiller jdnew...@dcn.davis.ca.us 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 )
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) ) ))
So my company has hired a few young McKinsey guys from overseas for a
couple of weeks to help us with a production line optimization. They
probably charge what I make in a year, but that's OK because I just
never have the time to really dive into one particular time, and I have
to hand it to the
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
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:
Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Cade, Brian
Sent: Wednesday, June 25, 2014 3:39 PM
To: Robert Latest
Cc: r-help@r-project.org
Subject: Re: [R] Simple permutation question
It is called sample(,replace=F), where the default argument
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
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of David L Carlson
Sent: Wednesday, June 25, 2014 4:02 PM
To: Cade, Brian; Robert Latest
Cc: r-help@r-project.org
Subject: Re: [R] Simple permutation question
Assuming you want all
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 ) {
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,
11 matches
Mail list logo