Reputation: 411
Consider I have the following list in which each element of the list is a vector and not a matrix (with s number of cols and rows) -
$a
[1] 1 2 3 4 5
$b
[1] 1 2 3 4 5
$c
[1] 1 2 3 4 5
I want to add across the elements (1,2 3..) of each vector (a, b, c) such that-
$Total
[1] 3 6 9 12 15
How do I do this in R?
Upvotes: 0
Views: 84
Reputation: 73405
Here is one way:
rowSums(simplify2array(lst))
where lst
is your list.
Upvotes: 1