I want to take slices of a multi-dimensional table (or array) without
knowing the number of dimensions in advance.
As a test I tried using (in this example a 3d table):
do.call(`[`, list(tbl, x,NULL,NULL)]
where I built the list on the fly. It works great as long as I only want
On Thu, Dec 22, 2011 at 4:34 AM, David A Vavra dava...@verizon.net wrote:
I want to take slices of a multi-dimensional table (or array) without
knowing the number of dimensions in advance.
As a test I tried using (in this example a 3d table):
do.call(`[`, list(tbl, x,NULL,NULL)]
On Dec 21, 2011, at 10:34 PM, David A Vavra wrote:
I want to take slices of a multi-dimensional table (or array) without
knowing the number of dimensions in advance.
As a test I tried using (in this example a 3d table):
do.call(`[`, list(tbl, x,NULL,NULL)]
Surely that was meant to be:
(This does imply you knew the number of dimensions was 3.)
Yes, at run time.
It looks as though the Nulls became 0's. So if you wanted to use
do.call(`[` then this succeeds:
do.call(`[`, list(tbl, x, 1:dim(tbl)[2], 1:dim(tbl)[3]) )
...
As does this using the empty comma approach:
From help([, package=base): An index value of NULL is treated as
if it were integer(0)..
Yeah, I should have read it better.
I don't think there is an easy way to achieve:
y[,2:3,1,drop=FALSE]
using do.call([) without explicitly specify the indices for that
missing dimension, i.e.
...
tibco.com
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of davavra
Sent: Thursday, December 22, 2011 10:31 AM
To: r-help@r-project.org
Subject: Re: [R] Indexing multi-dimensional table
From help([, package=base): An index
From: William Dunlap [mailto:wdun...@tibco.com]
You can build the 2nd argument to do.call with alist() instead.
alist() produces a list that you can use c() and subscripting on
to add or modify arguments. It is usually better to encapsulate
this sort of thing in a function like extract() that
7 matches
Mail list logo