Skip to content
Prev 260114 / 398502 Next

adding up elements within a list

Dear R users

I have a list, as follows:
$Devonian
[1] 4.8 4.2 9.5 5.7

$Ordovician
[1]  7.2  5.1 10.2  1.9

$Silurian
[1] 4.7 3.0 7.8 2.0 3.3 1.6 2.6 2.7


I want to write a loop that will sum up the values in each part, and give me a
vector containing the (in this case 3) summed values

this is what I have so far:

		for (i in 1:length(names(intvl.periods.myrs)) {
			my.new.vector<-sum(intvl.periods.myrs[i] }

This does not work and probably for obvious reasons.

Thanks
Martin