[R] How to subset a matrix?

Oliver Ruebenacker curoli at gmail.com
Tue Jun 12 18:58:53 CEST 2012


     Hello,

On Tue, Jun 12, 2012 at 12:44 PM, Michael <comtech.usa at gmail.com> wrote:
> Hi all,
>
> Lets say I have a matrix A which is m x n.
>
> I also have a mask matrix MASK which is m x n with values in T/F, where T
> values make a sub-matrix in regutangular shape...
>
> I applied B=A[MASK] and it didn't work as expected...
>
> Any thoughts?

  What did you expect and what happened?

  I'm assuming you did:

  B <- A[MASK]

  and I would expect the the result would be a vector whose size is
the number of elements in MASK that is TRUE. To get a matrix, you then
set the dim attribute (but I didn't test that).

     Take care
     Oliver

-- 
Oliver Ruebenacker
Bioinformatics Consultant (http://www.knowomics.com/wiki/Oliver_Ruebenacker)
Knowomics, The Bioinformatics Network (http://www.knowomics.com)
SBPAX: Turning Bio Knowledge into Math Models (http://www.sbpax.org)



More information about the R-help mailing list