do.call, missing arguments and [

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

do.call, missing arguments and [

hadley wickham
x <- array(1:30, c(4,5,3))
x[1,,]

How can I do the same thing with do.call?

do.call("[", list(x, 1)) == x[1]
do.call("[", list(x, 1, NULL, NULL)) == x[1, NULL, NULL]

I guess you can't, because of the special way that [ deals with arguments.

How can I index an array programmatically for arrays and indices of
varying dimensionality?

Thanks,

Hadley

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: do.call, missing arguments and [

Deepayan Sarkar
On 1/18/06, hadley wickham <[hidden email]> wrote:
> x <- array(1:30, c(4,5,3))
> x[1,,]
>
> How can I do the same thing with do.call?

do.call("[", list(x, 1, TRUE, TRUE))

seems to work for me.

Deepayan

>
> do.call("[", list(x, 1)) == x[1]
> do.call("[", list(x, 1, NULL, NULL)) == x[1, NULL, NULL]
>
> I guess you can't, because of the special way that [ deals with arguments.
>
> How can I index an array programmatically for arrays and indices of
> varying dimensionality?

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: do.call, missing arguments and [

hadley wickham
> do.call("[", list(x, 1, TRUE, TRUE))
>
> seems to work for me.

Oh! Of course.  I knew someone obvious was staring me in the face.

Thanks,

Hadley

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html