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, c(2,2,2))
> x[list(TRUE,TRUE,2)]
Error in x[list(TRUE, TRUE, 2)] : invalid subscript type 'list'

The only way I know is using do.call() but it's rather ugly. There
must be a better way!!

> do.call('[', c(list(x), TRUE, TRUE, 2))
     [,1] [,2]
[1,]   NA   NA
[2,]   NA   NA

Any idea?

Regards,
Ernest

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

Reply via email to