For row average you can post multiply by a vector of ones and then divide by the number of columns. For column average you pre multiply by a row vector of ones and then divide by the number of rows.
> r <- 10
> c <- 3
> rmat <- matrix(rnorm(r * c), nr = r, nc = c)
>
> # rowsums
> all.equal(c(rmat %*% rep(1, c)), rowSums(rmat))
[1] TRUE
>
> # colsums
> all.equal(c(rep(1, r) %*% rmat), colSums(rmat))
[1] TRUE