You can specify several input levels of the prop.table function, where 1 = row, 2 = column, 3 = strata, etc. etc.
A simple example:
test <- 1:8 dim(test) <- c(2,2,2) test , , 1 [,1] [,2] [1,] 1 3 [2,] 2 4 , , 2 [,1] [,2] [1,] 5 7 [2,] 6 8
Then you can do things like:
# % of all values in each stratum/sub-table prop.table(test,3)
There may be an easy way to deal with NA s, but the circular version should be to set them to 0 , and then reset as NA :
# set one of the values to NA as an example test[7] <- NA # do the procedure nas <- is.na(test) test[nas] <- 0 result <- prop.table(test,c(3,2)) result[nas] <- NA result , , 1 [,1] [,2] [1,] 0.3333333 0.4285714 [2,] 0.6666667 0.5714286 , , 2 [,1] [,2] [1,] 0.4545455 NA [2,] 0.5454545 1