This question already has an answer here:
- R: How to sum multiple columns of data frames in a list? 2 answers
I want to sum multiple columns of matrices in a list and only show the sum without showing the (calculation) input columns (similar to my former question on data frames). Thanks for the former answers, however I struggled to implement the ideas on matrices. Here an example:
ls <- list(matrix(c(1, 5, 3, 2), ncol=4), matrix(c(NA, 2, 7, 9), ncol=4))
countries <- c("a", "b", "c", "d")
ls <- lapply(ls, "colnames<-", countries)
my expected result is:
[[1]]
c new
[1,] 3 8
[[2]]
c new
[1,] 7 11
Any ideas how to do this column summation? Thanks