Use colSums instead of apply(..., 2, sum); suggested by Paul Fink.