If I have an array A
A <- array(0, c(4, 3, 5)) for(i in 1:5) { set.seed(i) A[, , i] <- matrix(rnorm(12), 4, 3) }
and if I have matrix B
set.seed(6) B <- matrix(rnorm(12), 4, 3)
The code for subtracting B from each matrix of array A will be:
d<-array(0, c(4,3,5)) for(i in 1:5){ d[,,i]<-A[,,i]-B }
However, what will be the code to perform the same calculation using a function from the "apply" family?
source share