Hello everyone- I have a 3-d array with the 1st dimension being monthly mean data that I would like to correlate with some time series index, for example, and save the coefficients in an array. The code I am currently running is.... rData <- array(0,c(73,144)) # array to store results for (i in 1:73) { for (j in 1:144) { rData[i,j] <- cor(slp[,i,j],y) } } Rather than running this analysis embedded with two outer loops, are there any more efficient ways of doing this? Many thanks! Maurice Maurice McHugh Department of Geography and Anthropology Louisiana State University Baton Rouge, LA [[alternative HTML version deleted]]
Maurice McHugh wrote:> Hello everyone- > > I have a 3-d array with the 1st dimension being monthly mean data that > I would like to correlate with some time series index, for example, and > save the coefficients in an array. > > The code I am currently running is.... > > > rData <- array(0,c(73,144)) # array to store results > for (i in 1:73) { > for (j in 1:144) { > rData[i,j] <- cor(slp[,i,j],y) > } > } > > Rather than running this analysis embedded with two outer loops, are > there any more efficient ways of doing this? > Many thanks!Don't know whether it's more efficient: You can try to apply() the function rcorr() in package "Hmisc" to your problem... Uwe Ligges> > > Maurice > > Maurice McHugh > Department of Geography and Anthropology > Louisiana State University > Baton Rouge, LA > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html