Re: [R] Equivalent of gtools::mixedsort in R base

2018-03-13 Thread Sebastien Bihorel
Thanks. - Original Message - From: "Gabor Grothendieck" <ggrothendi...@gmail.com> To: "Sebastien Bihorel" <sebastien.biho...@cognigencorp.com> Cc: r-help@r-project.org Sent: Monday, March 12, 2018 3:49:10 PM Subject: Re: [R] Equivalent of gtools::mixe

Re: [R] Equivalent of gtools::mixedsort in R base

2018-03-12 Thread Gabor Grothendieck
split any mixed columns into letter and number columns and then order can be used on that: DF <- data.frame(x = c("a10", "a2", "a1")) o <- do.call("order", transform(DF, let = gsub("\\d", "", x), no = as.numeric(gsub("\\D", "", x)),

Re: [R] Equivalent of gtools::mixedsort in R base

2018-03-12 Thread Sebastien Bihorel
l.com> Cc: "Sebastien Bihorel" <sebastien.biho...@cognigencorp.com>, "R-help" <r-help@r-project.org> Sent: Monday, March 12, 2018 2:11:03 AM Subject: Re: [R] Equivalent of gtools::mixedsort in R base x <- c( "a1", "a10", "a2" ) y &

Re: [R] Equivalent of gtools::mixedsort in R base

2018-03-12 Thread Sebastien Bihorel
tien.biho...@cognigencorp.com> Cc: r-help@r-project.org Sent: Monday, March 12, 2018 10:56:43 AM Subject: Re: [R] Equivalent of gtools::mixedsort in R base 1- mixedorder does not work in a "do.call(mixedorder, mydataframe)" call like the order function does This is tangential, b

Re: [R] Equivalent of gtools::mixedsort in R base

2018-03-12 Thread Sebastien Bihorel
.com> Cc: "R-help" <r-help@r-project.org> Sent: Monday, March 12, 2018 12:57:00 AM Subject: Re: [R] Equivalent of gtools::mixedsort in R base ??? > y <- sort( c("a1","a2","a10","a12","a100")) > y [1] "a1

Re: [R] Equivalent of gtools::mixedsort in R base

2018-03-12 Thread William Dunlap via R-help
1- mixedorder does not work in a "do.call(mixedorder, mydataframe)" call like the order function does This is tangential, but do.call(order, mydataframe) is not safe to use in a general purpose function either - you need to remove the names from the second argument: > d <-

Re: [R] Equivalent of gtools::mixedsort in R base

2018-03-12 Thread Jeff Newmiller
x <- c( "a1", "a10", "a2" ) y <- c( "b10", "b2", "a12", "ca1" ) DF <- expand.grid( x = x, y = y ) # randomize set.seed( 42 ) DF <- DF[ sample( nrow( DF ) ), ] # missing from gtools mixedrank <- function( x ) { seq.int( length( x ) )[ gtools::mixedorder(x) ] } o <- do.call( order, lapply( DF,

Re: [R] Equivalent of gtools::mixedsort in R base

2018-03-11 Thread Bert Gunter
??? > y <- sort( c("a1","a2","a10","a12","a100")) > y [1] "a1" "a10" "a100" "a12" "a2" > mixedsort(y) [1] "a1" "a2" "a10" "a12" "a100" **Please read the docs!** They say that mixedsort() and mixedorder() both take a **single vector** as the argument to be sorted or ordered and, as

[R] Equivalent of gtools::mixedsort in R base

2018-03-11 Thread Sebastien Bihorel
Hi, Searching for functions that would order strings that mix characters and numbers in a "natural" way (ie, "a1 a2 a10" instead of "a1 a10 a2"), I found the mixedsort and mixedorder from the gtools package. Problems: 1- mixedorder does not work in a "do.call(mixedorder, mydataframe)" call