Hopefully I understand your goal.
You have several datasets of the same dimension, and you want to calculate
the pairwise correlations of each dataset's row mean.
Depending on the dataset names, it may be easy to put all the data in a 1359
X 15 X 40 dimension array. Then, the following code would work.
DATA<-array(rnorm(1359*15*40),dim=c(1359,15,40))
means<-apply(DATA,3, function(x){ apply(x[,7:15],1,mean) } )
cor(means)
If your data is in list form, then the following code will work.
DATA2<-list(d1=data.frame(DATA[,,1]),d2=data.frame(DATA[,,2]),d3=data.frame(DATA[,,2]),d4=data.frame(DATA[,,4]))
# obviously your list would have all 40 datasets.
means2<-as.data.frame(lapply(DATA2,rowMeans))
cor(means2)
-tgs
On Tue, May 25, 2010 at 1:24 PM, <Steve_Friedman@nps.gov> wrote:
>
> 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@nps.gov
> Office (305) 224 - 4282
> Fax (305) 224 - 4147
>
> ______________________________________________
> 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.
>
[[alternative HTML version deleted]]