apply
works for this:
apply(obs,1:2,mean)
[,1] [,2] [,3] [,4]
[1,] 9 11 13 15
[2,] 10 12 14 16
or
aperm(apply(obs,1:2,summary),c(1,3,2))
(or apply(obs,2:1,summary)
as pointed out in comments)
with results:
[,1] [,2] [,3] [,4]
Min. 1 3 5 7
1st Qu. 5 7 9 11
Median 9 11 13 15
Mean 9 11 13 15
3rd Qu. 13 15 17 19
Max. 17 19 21 23
, , 2
[,1] [,2] [,3] [,4]
Min. 2 4 6 8
1st Qu. 6 8 10 12
Median 10 12 14 16
Mean 10 12 14 16
3rd Qu. 14 16 18 20
Max. 18 20 22 24
As requested you can get other marginal summaries
apply(obs,2,mean)
## [1] 9.5 11.5 13.5 15.5
(double-check: mean(obs[,1,])
is indeed 9.5 ...)