[R] matrix indexing
Andy Bunn
abunn at whrc.org
Wed Mar 15 17:04:53 CET 2006
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of tom wright
> Sent: Wednesday, March 15, 2006 6:04 AM
> To: R-Stat Help
> Subject: [R] matrix indexing
>
>
> 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.
Lie this?
matA <- matrix(c(5,2,1,2,4,2,4,3,4),3,3)
matB <- matrix(c(T,F,F,F,T,F,T,T,F),3,3)
matA[matB]
matA[!matB]
>
> Many thanks
> tom
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list