From tlumley at u.washington.edu  Fri May 29 23:54:32 2009
From: tlumley at u.washington.edu (Thomas Lumley)
Date: Fri, 29 May 2009 14:54:32 -0700 (PDT)
Subject: [Rd] Why change data type when dropping to one-dimension?
In-Reply-To: <4A2054BB.3010900@cs.dartmouth.edu>
Message-ID: <Pine.LNX.4.43.0905291454320.7202@hymn11.u.washington.edu>

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



[Rd] Why change data type when dropping to one-dimension?
Thomas Lumley