From h.wickham at gmail.com  Tue Nov 11 20:46:50 2008
From: h.wickham at gmail.com (hadley wickham)
Date: Tue, 11 Nov 2008 13:46:50 -0600
Subject: [Rd] is.matrix
In-Reply-To: <d8858f220811111135s644fb759nc150c4094ca11398@mail.gmail.com>
References: <d8858f220811111020j233d4d98j502c0079ace644e7@mail.gmail.com>
	<4919D240.4040904@acm.org>
	<f8e6ff050811111121u62cc1329s605ca0dcd521dfb2@mail.gmail.com>
	<d8858f220811111135s644fb759nc150c4094ca11398@mail.gmail.com>
Message-ID: <f8e6ff050811111146n3247f08fh8c819a155150d825@mail.gmail.com>

On Tue, Nov 11, 2008 at 1:35 PM, Daniel H?yer Iversen
<danielho at stud.ntnu.no> wrote:
>> That's confusing!  In what situations is x a matrix but does not have
>> a dim attribute?
>
> That was my point. I don't find it logical that
> is.matrix(a) gives FALSE but
> is.matrix(t( t(a) )) gives TRUE.
>
> I also think it would be more logical that
> a=c(1,1,2)
> dim(a) gives 3 1 instead of NULL,

In R t(t(a)) != a, because a vector is different to a 1d matrix.  This
is different to mathematical convention - you could argue that it
would have been wise to stick with convention, but there are some good
reasons for treating vectors differently to 1d matrices, and its too
late to change now.

Note that the following are all different in R:

a <- 1:3
b <- array(1:3, 3)
c <- array(1:3, c(3,1))
d <- array(1:3, c(3,1,1))
e <- array(1:3, c(3,1,1,1))
f <- array(1:3, c(3,1,1,1,1))

Hadley

-- 
http://had.co.nz/



[Rd] is.matrix
hadley wickham