[R] Array element is function of its position in the array
Greg.Snow at imail.org
Thu Dec 29 22:54:29 CET 2011
Does "vnew <- vold[,,ks]" accomplish what you want?
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
greg.snow at imail.org
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Asher Meir
> Sent: Thursday, December 29, 2011 1:58 PM
> To: r-help at r-project.org
> Subject: [R] Array element is function of its position in the array
> I want to create a new array which selects values from an original
> 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
> do this using a loop as follows:
> # Loop version:
> for(i1 in 1:nis)for(j1 in 1:njs)for(k1 in
> 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
> Would appreciate help with this issue.
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help