Skip to content
Back to formatted view

Raw Message

Message-ID: <E45CC400-F3DC-4C83-80BB-B57597CCB041@comcast.net>
Date: 2012-10-12T16:21:12Z
From: David Winsemius
Subject: Loss of dimensions in subsetting arrays
In-Reply-To: <20121012125220.60082air9p6af80k.mkarhune@webmail.helsinki.fi>

On Oct 12, 2012, at 2:52 AM, Markku Karhunen wrote:

> 
> Hi all,
> 
> I've been wondering for a long time why R drops the dimensions of an array/matrix when you try to take a subset of one column. I mean this:
> 
> dim(A)
> [1] 2 5 2
> B=A[1,,]
> dim(B)
> 5 2 # so now dim(B)[3] doesn't work
> C=B[2,]
> dim(C)
> NULL # so now nrow(C) doesn't work
> 
> Typically, you can get rid of this by writing as.matrix, as.array(...) but that generates extra lines of code. This is really annoying. Does anybody know how to turn this behaviour off?

Read the help page for:

 ?"["  # especially regarding the drop parameter.

--

David Winsemius, MD
Alameda, CA, USA