[R] Equivalent of gtools::mixedsort in R base
Sebastien Bihorel
sebastien.bihorel at cognigencorp.com
Mon Mar 12 18:44:07 CET 2018
Hi,
Point taken... although this error is not returned in older version of R (3.1.2 does not have any issue with your test case... not sure when the added layer of check was introduced).
From: "William Dunlap" <wdunlap at tibco.com>
To: "Sebastien Bihorel" <sebastien.bihorel at cognigencorp.com>
Cc: r-help at 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, 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 <- data.frame(method=c("New","New","Old","Old","Old"), result=5:1)
> do.call(order, d)
Error in match.arg(method) : 'arg' must be NULL or a character vector
> do.call(order, unname(as.list(d)))
[1] 2 1 5 4 3
Bill Dunlap
TIBCO Software
wdunlap [ http://tibco.com/ | tibco.com ]
On Sun, Mar 11, 2018 at 9:15 PM, Sebastien Bihorel < [ mailto:sebastien.bihorel at cognigencorp.com | sebastien.bihorel at cognigencorp.com ] > wrote:
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 like the order function does
2- gtools has not been updated in 2.5 years
Are you aware of an equivalent of this function in base R or a another contributed package (with correction of problem #1)?
Thanks
______________________________________________
[ mailto:R-help at r-project.org | R-help at r-project.org ] mailing list -- To UNSUBSCRIBE and more, see
[ https://stat.ethz.ch/mailman/listinfo/r-help | https://stat.ethz.ch/mailman/listinfo/r-help ]
PLEASE do read the posting guide [ http://www.r-project.org/posting-guide.html | http://www.R-project.org/posting-guide.html ]
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help
mailing list