http://www.r-bloggers.com/more-on-exploring-correlations-in-r/

cor() – table of correlations

cor.prob() – Replaces the upper triangul with the significance

flattenSquareMatrix(cor.prob(mydata)) – makes a table out of it

 

flattenSquareMatrix <- function(m) {
if( (class(m) != matrix) | (nrow(m) != ncol(m))) stop(Must be a square matrix.)
if(!identical(rownames(m), colnames(m))) stop(Row and column names must be equal.)
ut <- upper.tri(m)
data.frame(i = rownames(m)[row(m)[ut]],
j = rownames(m)[col(m)[ut]],
cor=t(m)[ut],
p=m[ut])
}