Hi,

I would like to sum some specific columns in my matrix- for example, my
matrix looks like this:
     [,1]  [,2]  [,3] [,4]  [,5]
[1,]    1   NA   NA   NA   NA
[2,]    2    1   NA    1   NA
[3,]    3    2    1     2    1
[4,]    4    3    2     3    2
[5,]   NA   NA   NA    4    3
[6,]   NA   NA   NA    5   NA

I would like to find the sum of the first two columns, the second two
columns and the last column:
i.e I am left with a vector of c(16, 18, 6).

I know about colSums and sum overall- I just wondered if this type of
grouping can be included somehow in a vector such as c(2,2,1)? I don't
really want to have to use a loop for this.

Many thanks Emma
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Summing-over-specific-columns-in-a-matrix-tp3179400p3179400.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to