[R] summing up a matrix
Christian Brandstätter
bran.chri at gmail.com
Fri Nov 18 17:03:42 CET 2016
Hi,
that should do:
mat <- rbind(c(20,200,100,50,100,30),
c(100,200,100,50,100,30),
c(50,200,100,50,100,30))
rownames(mat) <- c("2016-11","2016-12","2017-01")
t(apply(mat,1,cumsum))
Best,
Christian
Am 18.11.2016 um 16:16 schrieb Matthias Weber:
> Hello together,
>
> is it possible, to summing up a matrix?
> I have the following matrix at the moment:
>
> [,1] [,2] [,3] [,4] [,5] [,6]
> 2016-11 20 200 100 50 100 30
> 2016-12 100 200 100 50 100 30
> 2017-01 50 200 100 50 100 30
>
> Now I want to summing up the matrix in a new matrix.
>
> The result should look like the following:
>
> [,1] [,2] [,3] [,4] [,5] [,6]
> 2016-11 20 220 320 370 470 500
> 2016-12 100 300 400 450 550 580
> 2017-01 50 250 350 400 500 530
>
> Is it possible, to create that?
>
> Thanks for your help.
>
> Best regards.
>
> Mat
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
More information about the R-help
mailing list