[R] Simple permutation question

Robert Latest boblatest at gmail.com
Thu Jun 26 17:36:56 CEST 2014


On Wed, 25 Jun 2014 14:16:08 -0700 (PDT)
Jeff Newmiller <jdnewmil at 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 ) return( matrix( x, nrow=1 ) )
>    lst <- lapply( seq_along( x )
>                 , function( i ) {
>                     cbind( x[ i ], perm.jdn( x[ -i ] ) )
>                   }
>                 )
>    do.call(rbind, lst)
> }

Nice, exactly what I was looking for (including typo). Thanks!

robert



More information about the R-help mailing list