Open keithwlarson opened 12 years ago
Dear Keith,
Thanks for letting me know this, I will fix it as soon as I can find time.
Kind Regards, Avril
-----Original Message----- From: Keith Larson [mailto:reply@reply.github.com] Sent: Sun 12/11/2011 3:09 PM To: Coghlan, Avril Subject: [LittleBookofRMultivariateAnalysis] mosthighlycorrelated function error (#1)
Running the following function from your book on multvariate analysis results in the below error (at the bottom).
mosthighlycorrelated <- function(mydataframe,numtoreport) {
cormatrix <- cor(mydataframe)
diag(cormatrix) <- 0 cormatrix[lower.tri(cormatrix)] <- 0
numrows <- nrow(cormatrix) therownames <- rownames(cormatrix)
sorted <- sort(abs(cormatrix),decreasing=TRUE) for (i in 1:numtoreport) { corri <- sorted[i]
for (j in 1:(numrows-1)) { for (k in (j+1):numrows) { corrjk <- cormatrix[j,k] if (corri == abs(corrjk)) { rowname <- therownames[j] colname <- therownames[k] print(paste("i=",i,"variables",rowname,"and",colname,"correlation=",corrjk)) } } } } }
Error reported from r 2.14: Error in if (corri == abs(corrjk)) { : missing value where TRUE/FALSE needed
Reply to this email directly or view it on GitHub: https://github.com/avrilcoghlan/LittleBookofRMultivariateAnalysis/issues/1
Dear Keith,
I've finally got around to looking at this (sorry about the delay). I'm using 2.15.1 and don't get this error using this function on the wine[2:14] data-frame in the example on the webpage. Is this the input you are using? If not, please could you send me the input, so I can try to replicate the error?
Regards, Avril
So how was this fixed. I have the same error message
Running the following function from your book on multvariate analysis results in the below error (at the bottom).
mosthighlycorrelated <- function(mydataframe,numtoreport) {
find the correlations
cormatrix <- cor(mydataframe)
set the correlations on the diagonal or lower triangle to zero,
so they will not be reported as the highest ones:
diag(cormatrix) <- 0 cormatrix[lower.tri(cormatrix)] <- 0
find the dimensions of the matrix, and the row names:
numrows <- nrow(cormatrix) therownames <- rownames(cormatrix)
find the highest correlations
sorted <- sort(abs(cormatrix),decreasing=TRUE) for (i in 1:numtoreport) { corri <- sorted[i]
find the pair of variables with this correlation
for (j in 1:(numrows-1)) { for (k in (j+1):numrows) { corrjk <- cormatrix[j,k] if (corri == abs(corrjk)) { rowname <- therownames[j] colname <- therownames[k] print(paste("i=",i,"variables",rowname,"and",colname,"correlation=",corrjk)) } } } } }
Error reported from r 2.14: Error in if (corri == abs(corrjk)) { : missing value where TRUE/FALSE needed