I have a matrix of size 5000*5000, with 90% values as 0. Is there a ready-made solution available to calculate the mean, median for this matrix after excluding \'0\' ?
If you want median and mean of overall matrix then try following
median(x[x>0])
mean(x[x>0])
If you want median and mean row wise
apply(x,1,function(x){mean(x[x>0])})
apply(x,1,function(x){median(x[x>0])})
If you want median and mean coloumn wise
apply(x,2,function(x){mean(x[x>0])})
apply(x,2,function(x){median(x[x>0])})