2011/11/1 Ernest Adrogué :
> Hi,
>
> On ocasion, you need to subscript an array that has an arbitrary
> (ie. not known in advance) number of dimensions. How do you deal with
> these situations?
> It appears that it is not possible use a list as an index, for
> instance this fails:
>
>> x <- array(N
On 02/11/11 13:43, Ernest Adrogué wrote:
Sorry for not stating my problem in a more clear way. What I want is,
given an array of n dimensions, overwrite it by iteratating over its
"outermost" dimension... OK, in the previous example, I would like
to do
x<- array(NA, c(2,2,2))
for (i in 1:2) {
2/11/11 @ 13:10 (+1300), Rolf Turner escriu:
> On 02/11/11 11:14, Ernest Adrogué wrote:
> >Hi,
> >
> >On ocasion, you need to subscript an array that has an arbitrary
> >(ie. not known in advance) number of dimensions. How do you deal with
> >these situations?
> >It appears that it is not possible
1/11/11 @ 20:22 (-0400), Comcast escriu:
> Leaving the indices empty should give you what I'm guessing you want/expect.
>
> x[,,2]#. TRUE would also work, just not in a list.
Exactly, but this only works if x has three dimensions. What I want is
x[,,2] if x has three dimensions, x[,,,2] if
Here's a hack, but perhaps you might want to rethink what type of
output you want.
# Function:
g <- function(arr, lastSubscript = 1) {
n <- length(dim(arr))
commas <- paste(rep(',', n - 1), collapse = '')
.call <- paste('arr[', commas, lastSubscript, ']', sep = '')
eval(parse(text = .c
Yes,Ii did fail to read your post carefully and agree do.call seems
roundabout, but alternatives look even more tortured.
(You might want to include more context in the future.)
On Nov 1, 2011, at 8:30 PM, Ernest Adrogué wrote:
> 1/11/11 @ 20:22 (-0400), Comcast escriu:
>> Leaving the indices
Leaving the indices empty should give you what I'm guessing you want/expect.
x[,,2]#. TRUE would also work, just not in a list.
David.
On Nov 1, 2011, at 6:14 PM, Ernest Adrogué wrote:
> Hi,
>
> On ocasion, you need to subscript an array that has an arbitrary
> (ie. not known in advance)
On 02/11/11 11:14, Ernest Adrogué wrote:
Hi,
On ocasion, you need to subscript an array that has an arbitrary
(ie. not known in advance) number of dimensions. How do you deal with
these situations?
It appears that it is not possible use a list as an index, for
instance this fails:
x<- array(NA
8 matches
Mail list logo