[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: logical vectors and statistics functions
From: |
Rik |
Subject: |
Re: logical vectors and statistics functions |
Date: |
Wed, 09 Feb 2011 10:42:00 -0800 |
> On Wed, Feb 9, 2011 at 9:46 AM, John W. Eaton <address@hidden> wrote:
>> On 9-Feb-2011, Michael Creel wrote:
>>
>> | One change between 3.2.x and 3.4.0 that I have noticed is that mean(a)
>> | no longer works if a is a vector of booleans. sum(a) continues to
>> | work, however. Might be worth a mention unless the change is not
>> | intentional.
>>
>> Not intentional.
It actually was intentional. I tightened up the input validation routines
for all the base statistics functions. Previously there wasn't a lot of
checking and the routines would error out with strange messages when, in
fact, they had only been called in an incorrect manner.
The error message is pretty clear that mean is looking for a numeric
argument rather than a logical one:
mean (logical (1))
error: mean: X must be a numeric vector or matrix
One way to get around this is to cast the logical to a numeric class before
the call to mean() like so:
mean (double (x))
Of course, if we choose, we could also accept logical arguments and convert
them to double within the routines. If this happens it should probably
also go along with an overhaul of the routines to make sure that they
return an output of the same class as the input (single, double, etc.)
This won't work for logical inputs where we would always need to return a
numeric class. See this bug about not returning the same class
(http://savannah.gnu.org/bugs/?32168).
--Rik
- Re: logical vectors and statistics functions,
Rik <=