Is there a way to initialise an array using an expression/function in R -


is there easy way initialise array using function based on indexes of each cell within array?

for example if wanted create array values equal i+j+k such (for example):

> a[1,2,3]    6  > a[4,8,9]    21 

i'd along lines of:

a <- array( i+j+k , dim=c(10,10,10) , dimnames=list(i,j,k) )

do first need create array of size want, , apply function array (ie two-stage process)? or there way initilize values @ same time creating matrix?

nested outer calls seem trick (here 3 visibility):

 outer(outer(1:3,1:3,"+"),1:3,"+") 

or duplicate example:

> a=outer(outer(1:10,1:10,"+"),1:10,"+") > a[1,2,3] [1] 6 > a[4,8,9] [1] 21 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -