I want to create a new array which selects values from an original array
based on a function of the indices. That is:

I want to create a new matrix Vnew[i,j,k]=Vold[i,j,ks] where ks is a
function of the index elements i,j,k. I want to do this WITHOUT a loop.

Call the function "ksfunction", and the array dimensions nis,njs,nks. I can
do this using a loop as follows:

# Loop version:
Vnew<-array(NA,c(nis,njs,nks)
for(i1 in 1:nis)for(j1 in 1:njs)for(k1 in
1:nks)Vnew[i1,j1,k1]<-Vold[i1,k1,ksfunction(i1,j1,k1)]

I already know how to create an array of the ks's:
ksarray[i,j,k]=ksfunction(i,j,k)  # I have the array ksarray ready

I don't want a loop because nis,njs, and nks are pretty large and it takes
forever.

Would appreciate help with this issue.

        [[alternative HTML version deleted]]

______________________________________________
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