From csardi.gabor at gmail.com  Wed Aug  6 17:13:38 2014
From: csardi.gabor at gmail.com (=?UTF-8?B?R8OhYm9yIENzw6FyZGk=?=)
Date: Wed, 6 Aug 2014 11:13:38 -0400
Subject: [Rd] Subscripting Matrices
In-Reply-To: <53E244BE.8040208@his.com>
References: <53E244BE.8040208@his.com>
Message-ID: <CABtg=KmPC=CAWpztakWhiYCPSwWibGG43BfPQU-D9F0V-7ytTg@mail.gmail.com>

You want `drop=FALSE`:

> dim(ThinMatrix[TRUE, , drop=FALSE])
[1] 6 1

>From ?"[":

    drop: For matrices and arrays.  If ?TRUE? the result is coerced to
          the lowest possible dimension (see the examples).  This only
          works for extracting elements, not for the replacement.  See
          ?drop? for further details.

And R inferno 8.1.44:
http://www.burns-stat.com/pages/Tutor/R_inferno.pdf

Gabor

On Wed, Aug 6, 2014 at 11:07 AM, Terrence Ireland <kyzyl at his.com> wrote:
> There seems to be a result type difference when subscripting a 6 x 1 matrix
> as compared to a 3 x 2 matrix that is caused by the ncol = 1 compared to
> ncol > 1.
>
>> ThinMatrix <- matrix(1:6,ncol=1)
>> ThinMatrix
>      [,1]
> [1,]    1
> [2,]    2
> [3,]    3
> [4,]    4
> [5,]    5
> [6,]    6
>> FatMatrix <- matrix(1:6,ncol=2)
>> FatMatrix
>      [,1] [,2]
> [1,]    1    4
> [2,]    2    5
> [3,]    3    6
>> dim(ThinMatrix[TRUE,])
> NULL                                      #Though this value should be 6 1
>> dim(FatMatrix[TRUE,])
> [1] 3 2
>
> Thanks for your help.
>
> Terry Ireland
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Subscripting Matrices
=?UTF-8?B?R8OhYm9yIENzw6FyZGk=?=