How to sum a numeric list elements

You can use Reduce to successively apply a binary function to elements in a list.

Reduce("+",x)
     [,1] [,2]
[1,]    2    4
[2,]    3    5

Reduce("+",x)/length(x)
     [,1] [,2]
[1,]  1.0  2.0
[2,]  1.5  2.5

Leave a Comment