[R] Determine the dimension-names of an element in an array in R
Gabor Grothendieck
ggrothendieck at gmail.com
Sun Jul 26 01:56:30 CEST 2009
Try this:
> ix <- c(1, 3, 4, 2)
> mapply("[", dimnames(mydatastructure), ix)
[1] "S1" "T3" "U4" "V2"
On Sat, Jul 25, 2009 at 5:12 PM, Sauvik De<sauvik.stat at gmail.com> wrote:
> Hi:
> How can I extract the dimension-names of a pre-defined element in a
> multidimensional array in R ?
>
> A toy example is provided below:
> I have a 4-dimensional array with each dimension having certain length. In
> the below example, "mydatastructure" explains the structure of my data.
>
> mydatastructure = array(0, dim=c(length(b),length(z),length(x),length(d)),
> dimnames=list(b,z,x,d))
>
> where,
> b=c("S1","S2","S3","S4","S5")
> z=c("T1","T2", "T3")
> x=c("U1","U2","U3","U4")
> d=c("V1","V2")
>
> Clearly, "mydatastructure" contains many 0's.
> Now how can I get the dimension-names of any particular 0 ?
> That is, my input should be a particular 0 in the array "mydatastructure"
> (Suppose this 0 corresponds to S1,T3,U4 & V2 in the array). Then my output
> should be S1,T3,U4 & V2.
>
> The function "dimnames" didn't help me with the solution.
> Any idea will greatly be appreciated.
>
> Thanks for your time!
>
> Kind Regards,
> Sauvik
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>
More information about the R-help
mailing list