I a having a little trouble with vector or array operations.
I have three 3D arrays and i wanna find the average of them. How can i do that? we can\'t use mean()>
Here's an example which makes a vector of the three values, which makes na.omit usable:
vectorAverage <- function(A,B,C) {
Z <- rep(NA, length(A))
for (i in 1:length(A)) {
x <- na.omit(c(A[i],B[i],C[i]))
if (length(x) > 0) Z[i] = mean(x)
}
Z
}
Resulting in:
vectorAverage(A,B,C)
[1] 10.0 12.5 17.5 21.0 NA
Edited: Missed the NaN in the output of the first version.