[R] Quantiles with ordered categories
wdunlap at tibco.com
Tue Mar 14 22:00:15 CET 2017
You could round the quantiles of the codes of the ordered factor to
come up with a reasonable result. E.g.,
quantile.ordered <- function(x, ...)
> unCut <- log2(2:30)
> Cut <- cut(unCut, breaks=0:6, ordered_result=TRUE)
0% 25% 50% 75% 100%
1.000000 3.169925 4.000000 4.523562 4.906891
 (0,1] (3,4] (3,4] (4,5] (4,5]
Levels: (0,1] < (1,2] < (2,3] < (3,4] < (4,5] < (5,6]
On Tue, Mar 14, 2017 at 1:34 PM, Bert Gunter <bgunter.4567 at gmail.com> wrote:
> Bert Gunter
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> On Tue, Mar 14, 2017 at 12:36 PM, <matthias-gondan at gmx.de> wrote:
>> Dear R users,
>> This works:
>> quantile(1:10, probs=0.5)
>> This fails (obviously):
>> quantile(factor(1:10), probs=0.5)
>> But why do quantiles for ordered factors not work either?
>> quantile(ordered(1:10), probs=0.5)
>> Is it because interpolation (see the optional type argument) is not defined?
> Is there an elegant workaround?
> No. How can there be? By definition, all that is assumed by an ordered
> factor is an ordering of the categories. How can you "interpolate" in
> ordered(letters[1:3]) . ASAIK there is no "a.5" .
> -- Bert
>> Thank you.
>> Best wishes,
>> [[alternative HTML version deleted]]
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help