[R] General Question regarding Lists

Steve_Friedman at nps.gov Steve_Friedman at nps.gov
Tue May 25 19:24:44 CEST 2010


Hello,

Here is a general question that I think many of you will have insight to.

I have 40 independent dataframes. Each has a dimension of 1359 x 15.  For
example

>dim(meanAnnualWaterDepth)
> 1539  15

I need to calculate the average value for each dataframe but only for
columns 7: 15.  I can do this with apply as follows:

meanAnnualWaterDepth$Average <- apply(meanAnnualWaterDepth[7:15], 1, mean)

So far so good.

Next I need to generate a pairwise correlation matrix for each dataframe
using the calculated average value .  My approach has been to consider
calculating the average value first and then creating a "list" using code
similar to the following

hydrometrics_list <- list(meanAnnualWaterDepth$Average,
sevenDayWaterDepth$Average, discontinuousHydroperiod$Average)
#  abbreviated here,  it will have 40 objects when done

After this I need to run the pairwise correlations.

So is it more efficient to build the list first and calculate the averages
for each component of the list, or would it be more efficient to calculate
the averages first and then generate the list followed by the pairwise
correlations?

Can anyone suggest code to accomplish this?

I'm using R 2.10.1 on a windows machine.

Thanks for the feedback, much appreciated

Steve

Steve Friedman Ph. D.
Spatial Statistical Analyst
Everglades and Dry Tortugas National Park
950 N Krome Ave (3rd Floor)
Homestead, Florida 33034

Steve_Friedman at nps.gov
Office (305) 224 - 4282
Fax     (305) 224 - 4147



More information about the R-help mailing list