Re: [R] building a subscript programatically

2011-11-01 Thread Henrik Bengtsson
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

Re: [R] building a subscript programatically

2011-11-01 Thread Rolf Turner
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) {

Re: [R] building a subscript programatically

2011-11-01 Thread Ernest Adrogué
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

Re: [R] building a subscript programatically

2011-11-01 Thread Ernest Adrogué
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

Re: [R] building a subscript programatically

2011-11-01 Thread Dennis Murphy
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

Re: [R] building a subscript programatically

2011-11-01 Thread David Winsemius
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

Re: [R] building a subscript programatically

2011-11-01 Thread Comcast
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)

Re: [R] building a subscript programatically

2011-11-01 Thread Rolf Turner
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