Skip to content

Instantly share code, notes, and snippets.

@arcaravaggi
Created September 14, 2017 15:42
Show Gist options
  • Save arcaravaggi/004979408be4116505a49bd1d4c6e298 to your computer and use it in GitHub Desktop.
Save arcaravaggi/004979408be4116505a49bd1d4c6e298 to your computer and use it in GitHub Desktop.
Function for pairwise correlations across a data frame
# E.g. qDat.corr <- as.data.frame(cor.test.p(x))
cor.test.p <- function(x){
FUN <- function(x, y) cor.test(x, y)[["p.value"]]
z <- outer(
colnames(x),
colnames(x),
Vectorize(function(i,j) FUN(x[,i], x[,j]))
)
dimnames(z) <- list(colnames(x), colnames(x))
z
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment