On Mon, 6 Apr 2009, Steve Murray wrote:


Dear R Users,

I have 120 data frames of the format table_198601, table_198602... table_198612, table_198701, table_198702... table_198712 through to table_199512 (ie. the first 4 digits are years which vary from 1986 to 1995, and the final two digits are months which vary from 01 to 12 for each year).

I simply hope to find the means of column 3 of each of the 120 tables without having to type out mean(table_198601[3]) etc etc each time. How would I go about doing this? And how would I go about finding the mean of all the January months (01) from say 1986 to 1990?

Put all the tables in a list, then you can iterate over them, eg
 lapply(the_list, function(table) mean(table[,3))

You might also want a list of lists to maintain the annual structure, so that

januaries <- lapply(list_list, function(year) mean(year[[1]][,3]))

        -thomas


Finally, I hope to be able to plot (as a scatter graph) the values of column 1 against the mean of those from column 3 for all the months in the period 1989 to 1990 and then 1991 to 1995.

Any help offered would be very much appreciated.

Thanks,

Steve

_________________________________________________________________
[[elided Hotmail spam]]

______________________________________________
R-help@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.


Thomas Lumley                   Assoc. Professor, Biostatistics
tlum...@u.washington.edu        University of Washington, Seattle

______________________________________________
R-help@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.

Reply via email to