0

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?

tg110
  • 401
  • 1
  • 3
  • 15

1 Answers1

1

Here is one way:

rowSums(simplify2array(lst))

where lst is your list.

Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248