Re: [R] Simple permutation question

2014-06-27 Thread David Reiner
-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

Re: [R] Simple permutation question

2014-06-26 Thread Greg Snow
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")

Re: [R] Simple permutation question

2014-06-26 Thread Robert Latest
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

Re: [R] Simple permutation question

2014-06-25 Thread Jeff Newmiller
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

Re: [R] Simple permutation question

2014-06-25 Thread Jeff Newmiller
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 )

Re: [R] Simple permutation question

2014-06-25 Thread David L Carlson
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

Re: [R] Simple permutation question

2014-06-25 Thread Bert Gunter
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

Re: [R] Simple permutation question

2014-06-25 Thread David L Carlson
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

Re: [R] Simple permutation question

2014-06-25 Thread Ted Harding
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

Re: [R] Simple permutation question

2014-06-25 Thread Cade, Brian
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: