[Rd] quantile and IQR do not check for numeric input (PR#13631)

Simone Giannerini sgiannerini at gmail.com
Mon Mar 30 14:57:36 CEST 2009


Dear Thomas,

On Mon, Mar 30, 2009 at 1:50 PM, Thomas Lumley <tlumley at u.washington.edu> wrote:
> On Mon, 30 Mar 2009 sgiannerini at gmail.com wrote:
>
>> This report follows the post
>>
>> http://tolstoy.newcastle.edu.au/R/e6/devel/09/03/0760.html
>>
>> where it is shown that quantile() and IQR() do not work as documented.
>
> Nothing of the sort is shown! The thread argued that methods for these
> functions for ordered factors would be useful.

in the original thread  I initiated the matters were two (at least in
my intention)

1. quantile() and IQR() do not check for numeric input whereas
median() has a check (for a factor input). This has nothing to deal
with ordered factors

2. the opportunity of having methods for ordered factors for
quantile() and the like.

If, for some reason, you think that it is ok to have such check for
median but not for quantile and IQR then take this as a wishlist. BTW
also var() and the like do not check for factor input while mean() has
the check.

> x <- factor(letters[1:9])
> x
[1] a b c d e f g h i
Levels: a b c d e f g h i
> mean(x)
[1] NA
Warning message:
In mean.default(x) : argument is not numeric or logical: returning NA
> var(x)
[1] 7.5


Regards

Simone

>
>> In fact they do not check for numeric input even if the documentation says
>> =
>> :
>>
>> ?quantile
>> x      numeric vectors whose sample quantiles are wanted. Missing
>> values are ignored.
>>
>> ?IQR
>>
>> x       a numeric vector.
>>
>
> The documentation says that you are not allowed to pass anything except a
> numeric vector to quantile() and IQR(). It doesn't, for example, say you can
> pass an arbitrary vector that will be checked to see if it is numeric. If
> you have code that passes a factor to IQR(), the bug is in that code.
>
> On the other hand, as someone else has since reported, the 'missing values
> are ignored' statement in ?quantile is wrong (or at least incomplete).
>
>
>    -thomas
>
> Thomas Lumley                   Assoc. Professor, Biostatistics
> tlumley at u.washington.edu        University of Washington, Seattle
>
>
>



-- 
______________________________________________________

Simone Giannerini
Dipartimento di Scienze Statistiche "Paolo Fortunati"
Universita' di Bologna
Via delle belle arti 41 - 40126  Bologna,  ITALY
Tel: +39 051 2098262  Fax: +39 051 232153
http://www2.stat.unibo.it/giannerini/



More information about the R-devel mailing list