Q:

For loop to sum each column of a matrix in R

For the following matrix:
my_matrix<-matrix(seq(from=1,to=100,by=2))

If I wanted the sum of each column calculated I would just put the command as follows: colSums(my_matrix)
However, I need to create equivalence to colSums(my_matrix) without using the colSums function and instead use for loop. 
Some please help!!!

A:

If you explicitly want to use for loop here is one way : 
mat <- matrix(1:50, byrow = TRUE, ncol = 10)
all_vals <- numeric(ncol(mat))
for (i in seq(ncol(mat))) {
   all_vals[i] <- sum(mat[, i])
}

all_vals
#[1] 105 110 115 120 125 130 135 140 145 150

which gives same value as 
colSums(mat)
#[1] 105 110 115 120 125 130 135 140 145 150

