[R] adding up elements within a list

From: Martin Hughes <M.Hughes_at_bath.ac.uk>
Date: Tue, 17 May 2011 17:13:06 +0100

Dear R users

I have a list, as follows:

> intvl.period.myrs

$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

-- 
Martin Hughes
MPhil/PhD Research in Biology
Rm 1.07,  4south
University of Bath
Department of Biology and Biochemistry
Claverton
Bath    BA2 7AY
Tel: 01225 385 437
M.Hughes_at_bath.ac.uk
http://www.bath.ac.uk/bio-sci/biodiversity-lab/hughes.html

______________________________________________
R-help_at_r-project.org mailing list
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.
Received on Tue 17 May 2011 - 17:38:18 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 17 May 2011 - 17:50:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive