If you need an average and average total matrix, try doing
median(x[x>0]) mean(x[x>0])
If you want to see the median and middle row
apply(x,1,function(x){mean(x[x>0])}) apply(x,1,function(x){median(x[x>0])})
If you want middle and middle colonial wise
apply(x,2,function(x){mean(x[x>0])}) apply(x,2,function(x){median(x[x>0])})
source share