[R] subletting an array according to dimnames

Adams, Jean jvadams at usgs.gov
Fri Jun 2 14:00:16 CEST 2017


Have you tried P2["20", "10", "0"] ?

Jean

On Thu, Jun 1, 2017 at 3:10 PM, li li <hannah.hlx at gmail.com> wrote:

> Hi all,
>   I have a three dimensional array with the corresponding dimension names.
> I would like to subset the array according to the dimension names. For
> example,
> suppose I want to extract the values corresponding to A=20, B=10, C=0.  I
> know I
> can do:
>  P2[dimnames(P2)$A==20, dimnames(P2)$B==10, dimnames(P2)$C==0]
>
> But is there a better way for doing this? Thanks for your help!
>   Hanna
>
> > dimnames(P2)
>
> $A
>
> [1] "20" "25" "30" "35" "40"
>
>
> $B
>
> [1] "5"  "10" "15" "20" "25" "30" "35" "40"
>
>
> $C
>
> [1] "0"  "5" "10" "15" "20" "25" "30" "35"
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list