<br />
corstarsl <- function(x){<br />
require(Hmisc)<br />
x <- as.matrix(x)<br />
R <- rcorr(x)$r<br />
p <- rcorr(x)$P </p>
<p>## define notions for significance levels; spacing is important.<br />
mystars <- ifelse(p < .001, "***", ifelse(p < .01, "** ", ifelse(p < .05, "* ", " ")))</p>
<p>## trunctuate the matrix that holds the correlations to two decimal<br />
R <- format(round(cbind(rep(-1.11, ncol(x)), R), 2))[,-1] </p>
<p>## build a new matrix that includes the correlations with their apropriate stars<br />
Rnew <- matrix(paste(R, mystars, sep=""), ncol=ncol(x))<br />
diag(Rnew) <- paste(diag(R), " ", sep="")<br />
rownames(Rnew) <- colnames(x)<br />
colnames(Rnew) <- paste(colnames(x), "", sep="") </p>
<p>## remove upper triangle<br />
Rnew <- as.matrix(Rnew)<br />
Rnew[upper.tri(Rnew, diag = TRUE)] <- ""<br />
Rnew <- as.data.frame(Rnew) </p>
<p>## remove last column and return the matrix (which is now a data frame)<br />
Rnew <- cbind(Rnew[1:length(Rnew)-1])<br />
return(Rnew)<br />
}<br />
</p>