mat<-matrix(1:9,nrow=3,ncol=3)
for(i in 1:3){
print(colSums(mat[1:i,]))
}
I'm trying to calculate mean of colSums of part of a matrix.
How do I avoid for loop in this case? The answer may be similar to the code below but I don't know how to proceed.
apply(mat,2,function(x) colSums(mat[]))
Thanks in advance!