problem related to column and row "mean" to write altogether.

Hello Team,

I am having problem while making matrix. In below example, I want mean for column and row together but don't know how to do it. For eg. I have got the mean for column but did not get the mean for row. Can somebody help me?
m <- matrix(c(200, 100, 0, 80, 200, 20, 20, 80, 100, 0, 20, 180), nrow = 3, ncol = 4)

RowSum <- rowSums(m)
ColSum <- colSums(m)
mean <- RowSum/ncol(m)
mean1 <- ColSum/nrow(m)
m2 <- cbind(m, mean)
m2

m3 <- rbind(m2, c(mean1, sum(mean1)))
m3

rownames(m3) <- c("0-5", "5-10", "10-30", "mean")
colnames(m3) <- c("1-10", "10-21", "21-40", "40-60", "mean")
m3 <- round(m3, digits = 0)
View(m3)

Thanks in advance.

Regards
Rahul Kumar Singh

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.