A great example of why you need to read and follow the posting guide
-- this is a plain text list: NO HTML.

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Mar 3, 2017 at 9:59 AM, exponential <exponent...@o2.pl> wrote:
> Hi!   I&#39;ve tried on SO, but without success. Maybe you will be able to 
> help.   I have the following array (I use 3-dimensional in this example for 
> simplicity, but it can be 3+ dims - 10,11 or more):   a &lt;- c(&#39;a1&#39;, 
> &#39;a2&#39;, &#39;a3&#39;)  b &lt;- c(&#39;bb&#39;, &#39;bbb&#39;)  c &lt;- 
> c(&#39;C&#39;, &#39;CC&#39;, &#39;CCC&#39;)   dimNa &lt;- list(&#39;a&#39; = 
> a, &#39;b&#39; = b, &#39;c&#39; = c)   outputArray &lt;- array(NA,            
>       unname(sapply(dimNa, function(x) length(x), simplify = T)),             
>      unname(dimNa))   I can subset it using name from one dimension manually, 
> like:   &gt; outputArray[,&#39;bb&#39;,]      C CC CCC  a1 NA NA  NA  a2 NA 
> NA  NA  a3 NA NA  NA   or   &gt; outputArray[,,&#39;CCC&#39;]     bb bbb  a1 
> NA  NA  a2 NA  NA  a3 NA  NA   I would like to write a function which subsets 
> particular named element from one dimension (I mean I don&#39;t expect one 
> dimension as a result by slicing using one named element, if tha!
 t makes sense). Something like     myfunc &lt;- function(inputArray, 
namedElement)   thus I can call it (using above example):   myfunc(outputArray, 
&#39;bb&#39;)   or    myfunc(outputArray, &#39;CCC&#39;)   to get identical as 
above results.   I know how to deal with finding to which dimension 
&#34;namedElement&#34; belongs (in my case all names are unique).   The 
question is how to subset it from the array? One idea is to construct what is 
inside [ ] (in example: ,&#39;bb&#39;, or ,,&#39;CCC&#39;). I&#39;ve tried 
something like this:    inputDims &lt;- &#34;,,&#39;CCC&#39;&#34;   
outputArray[parse(text=inputDi   But this doesn&#39;t work. Maybe different 
approach should be used...   Any ideas are welcome:)!   Cheers!
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.

______________________________________________
R-help@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.

Reply via email to