From marc_schwartz at me.com  Wed Aug  6 17:17:28 2014
From: marc_schwartz at me.com (Marc Schwartz)
Date: Wed, 06 Aug 2014 10:17:28 -0500
Subject: [Rd] Subscripting Matrices
In-Reply-To: <53E244BE.8040208@his.com>
References: <53E244BE.8040208@his.com>
Message-ID: <4513EF07-08D4-48B7-A067-28C0E02FB35C@me.com>

On Aug 6, 2014, at 10: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


Hi,

This question really should have gone to R-Help, not R-Devel and it is a FAQ:

  http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-my-matrices-lose-dimensions_003f

> str(ThinMatrix[TRUE,])
 int [1:6] 1 2 3 4 5 6


Regards,

Marc Schwartz



[Rd] Subscripting Matrices
Marc Schwartz