From jv at cs.dartmouth.edu  Sat May 30 00:17:28 2009
From: jv at cs.dartmouth.edu (Jason Vertrees)
Date: Fri, 29 May 2009 18:17:28 -0400
Subject: [Rd] Why change data type when dropping to one-dimension?
In-Reply-To: <Pine.LNX.4.43.0905291454320.7202@hymn11.u.washington.edu>
References: <Pine.LNX.4.43.0905291454320.7202@hymn11.u.washington.edu>
Message-ID: <4A205EF8.5010604@cs.dartmouth.edu>

Thomas Lumley wrote:
> On Fri, 29 May 2009, Jason Vertrees wrote:
> 
>> My question is: why does the paradigm of changing the type of a 1D
>> return value to an unlisted array exist?  This introduces boundary
>> conditions where none need exist, thus making the coding harder and
>> confusing.
>>
>> For example, consider:
>>  > d = data.frame(a=rnorm(10), b=rnorm(10));
>>  > typeof(d);            # OK;
>>  > typeof(d[,1]);          # Unexpected;
>>  > typeof(d[,1,drop=F]);    # Oh, now I see.
> 
> It does make it harder for programmers, but it makes it easier for
> non-programmers.  In particular, it is convenient to be able to do
> d[1,1] to extract a number from a matrix, rather than having to
> explicitly coerce the result to stop it being a matrix.
> 
> At least the last two times this was discussed, there ended up being a
> reasonable level of agreement that if someone's life had to be made
> harder the programmers were better able to cope and that dropping
> dimensions was preferable.
> 
>     -thomas
> 
> Thomas Lumley            Assoc. Professor, Biostatistics
> tlumley at u.washington.edu    University of Washington, Seattle


Thomas,

Thanks for the quick response.  I agree that extracting a number from a
matrix/frame should result in a number not a matrix/frame.  But, why do
that for a 1D array of numbers?  In my example,
  > d[,1];
is an array, not a single number.  How does that help the novice user?

I guess I just don't like the idea that the default result is to act
unexpectedly and that a flag or boundary-conditional code is needed to
"do the right thing".

Regardless that's how it is, so I just need to learn the pitfalls for
where that occurs.

Thanks again,

-- Jason

-- 

Jason Vertrees, PhD

Dartmouth College : jv at cs.dartmouth.edu
Boston University : jasonv at bu.edu

PyMOLWiki : http://www.pymolwiki.org/



[Rd] Why change data type when dropping to one-dimension?
Jason Vertrees