T test 3D array

369 views Asked by At

I have a 3D array of data defined by [i,j,k] and want to perform a single sample t-test on the 3rd dimension, [k], testing for difference from 0. Ideally, the results would be returned as a matrix of t values of size [i,j]. Unfortunately, I do not know the size of the 3D array beforehand.

set.seed(1999)
i <- 4; j <- 2; k <- 6
df <- runif((i*j*k))
ar <- array(df, c(i, j, k))
1

There are 1 answers

0
Rui Barradas On

If I understand it correctly, try the following.

tt <- apply(ar, 1:2, t.test)
apply(tt, 1, function(x) lapply(x, identity))