I am trying to add all elements to a matrix. This is an example of my matrix (the actual matrix is โโbigger):
m = matrix(c(528,479,538,603),nrow=2,ncol=2) m AB male 528 538 female 479 603
I am trying to do:
sum.elements = colSums(colSums(m))
but it gives the following error:
Error in colSums (colSums (m)): 'x' must be an array of at least two Dimensions
I tried to do:
x = colSums(m) sum.elements = x[1] + x[2]
but that would be very long if you have a matrix with 100 columns ...
Any help would be greatly appreciated!
source share