Re: [R] How to apply a function to a multidimensional array based on its indices

2012-05-15 Thread math_daddy
Thanks for the help, this worked great! Much appreciated. -- View this message in context: http://r.789695.n4.nabble.com/How-to-apply-a-function-to-a-multidimensional-array-based-on-its-indices-tp4629940p4630068.html Sent from the R help mailing list archive at Nabble.com. __

Re: [R] How to apply a function to a multidimensional array, based on its indices

2012-05-15 Thread Rui Barradas
can be large. Rui Barradas Em 15-05-2012 11:00, r-help-requ...@r-project.org escreveu: Date: Mon, 14 May 2012 13:22:11 -0400 From: David Winsemius To: math_daddy Cc: r-help@r-project.org Subject: Re: [R] How to apply a function to a multidimensional array based on its indices Message-ID: &

Re: [R] How to apply a function to a multidimensional array based on its indices

2012-05-14 Thread David Winsemius
On May 14, 2012, at 10:09 AM, math_daddy wrote: Hello. I have a 4 dimensional array and I want to fill in the slots with values which are a function of the inputs. Through searching the forums here I found that the function "outer" is helpful for 2x2 matrices but cannot be applied to gener

Re: [R] How to apply a function to a multidimensional array based on its indices

2012-05-14 Thread Rui Barradas
Hello, Try K <- array(0,dim=c(2,2,2,2)) #dimensions will be much larger for(x1 in 1:2){ for(y1 in 1:2) { for(x2 in 1:2){ for(y2 in 1:2) { K[x1,y1,x2,y2] <- x1*y2 - sin(x2*y1) #this is just a dummy function. } } } } fun <- function(x){ x1 <- x

[R] How to apply a function to a multidimensional array based on its indices

2012-05-14 Thread math_daddy
Hello. I have a 4 dimensional array and I want to fill in the slots with values which are a function of the inputs. Through searching the forums here I found that the function "outer" is helpful for 2x2 matrices but cannot be applied to general multidimensional arrays. Is there anything which can a