[R] matrix indexing
Marc Schwartz (via MN)
mschwartz at mn.rr.com
Wed Mar 15 17:02:23 CET 2006
On Wed, 2006-03-15 at 06:03 -0500, tom wright wrote:
> Can someone please give me a pointer here.
> I have two matrices
>
> matA
> A B C
> 1 5 2 4
> 2 2 4 3
> 3 1 2 4
>
> matB
> A B C
> 1 TRUE FALSE TRUE
> 2 FALSE TRUE TRUE
> 3 FALSE FALSE FALSE
>
> how do I extract all the values from matA where the coresponding entry
> in matB == TRUE (or FALSE), perferably in vector form.
>
> Many thanks
> tom
The subsetting/indexing is premised on the index values being TRUE,
thus:
> matA[matB]
[1] 5 4 4 3
> matA[!matB]
[1] 2 1 2 2 4
HTH,
Marc Schwartz
More information about the R-help
mailing list