I would like to extract elements from a deeply embedded list into an array.
For example, I am implementing a t-test at each grid point (2×2) and would like to save each p-value from the t-test into a 2×2 array without a nested for loop. (My data set is quite large.)
z <- rnorm(2*2*2)
z <- array(z, dim=c(2,2,2))
ttest <- apply(z, c(1,2), function(x) t.test(x, mu=.3, var.equal=TRUE))
ttest[[1,1]]$p.value # extracts p-value at the first grid point.
# This would be the [1,1] element in my desired array.
Do you want something like this: