This is is just a quick function to get a p value from a correlation coefficient and n (or df). I’m sure it exists somewhere else - but it turned out to be quicker to write it than search for it. Useful for when checking student work or reviewing papers.

p.to.r <- function(rho.hat, n=NULL, df=n-2, two.sided=TRUE) {
    
    t <- abs(rho.hat) / sqrt((1-rho.hat^2)/df)
    if (two.sided==TRUE) pval <- pt(t, df, lower.tail=FALSE)*2
    if (two.sided==FALSE) pval <- pt(t, df, lower.tail=FALSE)
    pval
    }
    
p.to.r(.296, df=10)
## [1] 0.3502245
p.to.r(.377, n=40)
## [1] 0.01648587