[R] another do.call() problem.

Robin Hankin rksh at soc.soton.ac.uk
Fri Mar 12 10:10:51 CET 2004


Hi everyone

suppose I have

a <- array(1:256,rep(4,4))

and want to access a[1,2,3,1] by the vector c(1,2,3,1).  As per 
yesterday, I can use do.call():

a[1,2,3,1] == do.call("[",c(list(a),c(1,2,3,1)))

Now how do I apply the above technique (or indeed any other technique!)  to get

a[1,2,3,]

[1]  37 101 165 229

from a vector like c(1,2,3,0) or c(1,2,3,NULL) or c(1,2,3,NA)?



OBattempts:

do.call("[",c(list(a),c(1,2,3)))
do.call("[",c(list(a),c(1,2,3),NULL))
do.call("[",c(list(a),c(1,2,3,NULL)))
do.call("[",c(list(a),c(1,2,3,",")))

none of these give what I want.

Anyone?
-- 
Robin Hankin
Uncertainty Analyst
Southampton Oceanography Centre
SO14 3ZH
tel +44(0)23-8059-7743
initialDOTsurname at soc.soton.ac.uk (edit in obvious way; spam precaution)




More information about the R-help mailing list