[R] Taking slices with tensorA

Gabor Grothendieck ggrothendieck at gmail.com
Wed Dec 3 05:07:00 CET 2008


There is section on argument matching in ?"["



On Tue, Dec 2, 2008 at 10:49 PM, John Tillinghast <tilling at gmail.com> wrote:
> I've set up a simple tensor with indices 'a' and 'b'.
>
>> ftable(B)
>   b           u           v           w           x           y
> a
> a1   0.001868954 0.403345197 0.030088185 0.137252368 0.142634612
> a2   0.396935972 0.945219795 0.068828465 0.314180585 0.446338719
> a3   0.752412200 0.748810918 0.125532631 0.471686930 0.345062348
> a4   0.191103000 0.536607533 0.257740399 0.525900194 0.976841803
> a5   0.581585362 0.679024312 0.333035405 0.460748770 0.438562927
>
> Now I try two ways of taking the subtensor with index 'b'=2:
>
>> B[a=1:5, b=2]
> [1] 0.4033452 0.9452198 0.7488109 0.5366075 0.6790243
> attr(,"class")
> [1] "tensor"
>> B[b=2, a=1:5]
> [1] 0.39693597 0.94521979 0.06882847 0.31418058 0.44633872
> attr(,"class")
> [1] "tensor"
>
> This does not seem consistent with the spirit of having named indices whose
> order does not matter.
>
> Now, what I *really* want to do is take the subtensor where 'b' has the name
> 'u' or 'w' (for instance)...
>
> Any suggestions?
>
>        [[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