I have a large array in R, let's say,
A = array(rnorm(100*100*30*30*100),dim=c(100,100,30,30,100))
I would like to find the first entry in the 4th dimension that is less than 1:
first_entry = apply(A,c(1,2,3,5),function(x) min(which(x < 1)))
Because the array is so large, this takes a while, around 20 seconds on my computer, and I'm going to do this for lots of arrays in the future. A for loop is about the same speed. I've also tried using parApply, but it takes around the same time, if not longer. Probably my function is not "complex" enough for parallelization to realize a speed gain. Is there a faster way to do this? And actually, what I would like to be able to do ideally is set the values in another array B (that has the same dimensions as A) to 0. So, something like,
B[first_entry] = 0
Note that this doesn't work given the current output of "apply" (above), since the dimension of first_entry there is 100x100x30x100.